Delphi Prism 中 TList 的替代品。
我正在将用 Delphi 2007 编写的应用程序迁移到 Delphi Prism,哪个是替换 TList 类的最佳选择?
提前致谢。
再见。
I am migrating an application written in Delphi 2007 to Delphi Prism, which is the best option to replace the TList class?
Thanks in advance.
Bye.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有指定您是指普通 TList 还是 D2009 中与泛型一起引入的通用 TList,尽管我有一种感觉它是普通 TList。
如果您想使用泛型,请使用 List 。这意味着您不必每次从列表中删除某些内容时都进行手动类型转换。一般来说,您可能会想要使用这个,除非您有特定的理由不这样做。如果您已经在 Delphi 应用程序中使用 TList,您也应该使用它 - 如果没记错的话,CodeGear 在 D2009 中添加泛型时特意采用了 .NET List 的接口。
如果您想要一个仅存储对象的非通用版本(很像 TList),请查看 ArrayList。这更接近于您当前的实现(假设普通 TList),但是您失去了使用泛型可以获得的编译时类型安全性。
You don't specify if you mean the plain TList or the generic TList introduced with generics in D2009, although I have a feeling it's the plain TList.
Use List<T> if you want to use generics. That means you don't have to do manual typecasting every time you take something out of your list. In general, you would probably want to use this one unless you have a specific reason not to. You should also use this if you are already using TList in your Delphi application - if memory serves, CodeGear deliberately adapted the interface from the .NET List when adding generics in D2009.
If you want a non-generic version, which just stores Objects (much like TList), look at ArrayList. This maps more closely to your current implementation (assuming plain TList), but you lose the compile-time type safety you can get from using generics.