Delphi:泛型和 TObjectList
我创建了一个像
TMyClass = class(TObject)
private
FList1: TObjectList<List1>;
FList2: TObjectList<List2>;
public
end;
现在这样的类,我想要一个方法FillArray(Content);
,最好应该实现一次,即没有重载。我相信使用泛型是可能的,但我对这些野兽缺乏经验,无法实际实现它。有人知道吗?提前致谢!
I've created a class like
TMyClass = class(TObject)
private
FList1: TObjectList<List1>;
FList2: TObjectList<List2>;
public
end;
Now, I want a method FillArray(Content);
, which preferably should be implemented once, i.e. no overload. I believe this is possible using generics, but I'm too inexperienced with these beasts to actually implement it. Do anyone have a clue? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信以下内容仅适用于 Delphi 2010。因为它取决于 TArray的声明在系统单元中,看起来像这样:
这是我开发的用于帮助 TArray 到 List 转换的单元,
因为 TList是 TObjectList的父类。这应该与 TObjectList一起使用虽然我还没有尝试过。
The following I believe will only work in Delphi 2010. As it depends on the declaration of TArray<T> in the system unit, that looks like this:
Here is unit I have developed to help with TArray to List conversions
Since TList<T>is the parent class for TObjectList<T> this should work with TObjectList<T> although I have not tried it.