德尔福中的通用容器
我正在尝试这样做:
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;
其中 FindSenderIndex 函数(仍然实现它)将返回 ASender 与 MyObj[i].Sender< 匹配的项目的索引/强>。但是在编译时我收到此错误消息:“E2086 Type 'TList
我做错了什么?提前致谢。
Pdta:您能给我一些关于如何使用对象容器(TObjectList
的好例子吗?
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 in advance.
Pdta: May you give me some good examples about how to use Object Containers (TObjectList<T:class>=class(TList<T>))
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这看起来像是编译器中的错误。我可以在 Delphi 2010 下重现这一点。请在 QC 中报告。
不过,解决方法很简单。 相反,声明
一下,它就起作用了。
至于
TObjectList
,它与TList
完全相同,只是它只接受对象,并且添加了 OwnsObjects 属性。如果 OwnsObjects 设置为 True,那么当您释放列表或调用Clear
或Delete
方法时,它将释放从列表中删除的所有对象。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
instead, and it works.
As for
TObjectList<T>
, it's exactly the same asTList<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 theClear
orDelete
methods, it will free all the objects removed from the list.