我想TList
在 Delphi 中使用 multi 。例如:
var
temp1List : TList;
temp2List : TList;
begin
temp1List := TList.Create;
temp2List := TList.Create;
temp1List.add(temp2List);
end;
我认为这是不正确的,因为TList
接受参数作为Pointer
值。
有没有办法使用 multi TList
?
TList<T>
改为查看 Generic ,例如:
uses
..., System.Classes, System.Generics.Collections;
var
temp1List : System.Generics.Collections.TList<System.Classes.TList>;
temp2List : System.Classes.TList;
begin
temp1List := System.Generics.Collections.TList<System.Classes.TList>.Create;
temp2List := System.Classes.TList.Create;
temp1List.Add(temp2List);
// don't forget to free them when you are done...
temp1List.Free;
temp2List.Free;
end;
或者,因为TList
它是一个类类型,你可以使用TObjectList<T>
它,并利用它的OwnsObjects
特性:
uses
..., System.Classes, System.Generics.Collections;
var
temp1List : System.Generics.Collections.TObjectList<System.Classes.TList>;
temp2List : System.Classes.TList;
begin
temp1List := System.Generics.Collections.TObjectList<System.Classes.TList>.Create; // takes Ownership by default
temp2List := System.Classes.TList.Create;
temp1List.Add(temp2List);
// don't forget to free them when you are done...
temp1List.Free; // will free temp2List for you
end;