创建一条记录来保存所有信息:
type
TFrameInfo = record
Frame: TCustomFrame;
Foo: string;
Bar: Integer;
end;
Run Code Online (Sandbox Code Playgroud)
把它放在一个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;
Run Code Online (Sandbox Code Playgroud)
然后在此举行TObjectList<TFrameInfo>具有OwnsObjects设置为True.