Generic Containers in Delphi
I'm trying to do this:
type
TItemRec = record
Sender : TAction;
OwnerPack : HModule;
ChildForm : TForm;
end;
TRecList = TList<TItemRec>;
THelperList = class helper for TRecList
function FindSenderIndex(ASender: TAction): Int16;
end;
var
MyObj : TRecList;
Where FindSenderIndex function (implementing it still) will return index of the item where ASender matchs with MyObj[i].Sender. But when compiling I get this error message: "E2086 Type 'TList<T>' is not yet completely defined"
What am I doing bad? Thanks开发者_如何学C in advance.
Pdta: May you give me some good examples about how to use Object Containers (TObjectList<T:class>=class(TList<T>))
?
This looks like a bug in the compiler. I'm able to reproduce this under Delphi 2010. Please report it in QC.
The workaround's simple enough, though. Declare
TRecList = class(TList<TItemRec>);
instead, and it works.
As for TObjectList<T>
, it's exactly the same as TList<T>
except that it will only accept objects, and it adds the OwnsObjects property. If OwnsObjects is set to True, then when you free the list, or call the Clear
or Delete
methods, it will free all the objects removed from the list.
精彩评论