Delphi (VCL) 泛型和数据绑定?
有谁知道Delphi XE(我在这里说的是VCL)是否有任何与数据感知控件一起使用的通用集合类?换句话说,是否存在任何通用类,例如 TObjectList<> ?可以分配给 TDataSource.DataSet 或类似的东西?
谢谢。
担
Does anyone know if Delphi XE (I'm talking VCL here) has any Generic Collection classes that work with data-aware controls? In other words, are there any Generic classes, like TObjectList<> that can be assigned to TDataSource.DataSet, or something similar?
Thanks.
Dan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您可以,使用 ObjectDataSet 概念,我认为您最终将不得不基于自己的实现以链接的示例代码为起点。
示例代码展示了如何融合常规非通用 TObjectList 和 TDataSet 的概念。它使用 RTTI 来提供您希望附加到它的任何对象类型的任何列表。它使用 RTTI 并且不需要使用 Generics,而是要求您从 TPersistent 继承。
它的不好的一面是,我已经使用过它,并且我永远不会再使用它。生成的代码很混乱,速度很慢,而且模型很糟糕。下次,我将远离数据感知控件,而简单地使用具有虚拟控件的容器,例如 VirtualTreeView 和 ExGridView。
我看不出为什么你不能以上面的代码作为基础,并将泛型与数据绑定结合起来,但我可以看到很多你不应该这样做的原因。
Yes you can, using an ObjectDataSet concept, which I think you would end up having to implement yourself based on the linked sample code as a starting place.
The sample code shows how to fuse the concept of a regular non-generic TObjectList and a TDataSet. It uses RTTI to provide any list you wish to attach to it, of any object type. It uses RTTI and does not need to use Generics, rather it requires that you inherit from TPersistent.
The bad side of it, is that I have used it, and I would never use it again. The resulting code was a mess, was slow, and the model was horrible. Next time, I would stay away from data aware controls, and simply use containers with VIRTUAL CONTROLs like VirtualTreeView, and ExGridView.
I see no reason why you couldn't start with the above code as a base, and combine generics with data binding, but I can see lots of reasons why you shouldn't.
要获得其他意见:
它们都可以按预期使用具有绑定功能的通用集合类,这使得将数据暴露给可视化组件变得非常容易。
To have another opinion:
They both can use Generic Collection classes as expected with binding capablity which makes exposing data to visual components quite easy.