我正在使用TObjectList TCustomFrame存储TCustomFrames.现在我想在同一列表中存储有关TCustomFrame的更多信息.记录会很好. 您希望将哪个delphi类存储在同一列表中的TCustomFrame和记录? TCustomFrames和记
您希望将哪个delphi类存储在同一列表中的TCustomFrame和记录?
TCustomFrames和记录将在运行时添加.
创建一条记录来保存所有信息:type
TFrameInfo = record
Frame: TCustomFrame;
Foo: string;
Bar: Integer;
end;
在TList< TFrameInfo>中保留它.
我注意到你使用的是TObjectList< T>而不是TList< T>.这样做的唯一好处是,如果您将OwnsObjects设置为True.但这似乎不太可能,因为我怀疑列表是否真正负责GUI对象的生命周期.作为未来的注释,如果您发现自己使用TObjectList< T>如果将OwnsObjects设置为False,那么您也可以切换到TList< T>.
现在,如果您确实需要列表来控制生命周期,那么您最好使用类而不是TFrameInfo的记录.
type
TFrameInfo = class
private
FFrame: TCustomFrame;
FFoo: string;
FBar: Integer;
public
constructor Create(AFrame: TCustomFrame; AFoo: string; ABar: Integer);
destructor Destroy; override;
property Frame: TCustomFrame read FFrame;
// etc.
end;
constructor TFrameInfo.Create(AFrame: TCustomFrame; AFoo: string; ABar: Integer);
begin
inherited Create;
FFrame := AFrame;
// etc.
end;
destructor TFrameInfo.Destroy;
begin
FFrame.Free;
inherited;
end;
然后将其保存在TObjectList< TFrameInfo>中.将OwnsObjects设置为True.
