简体   繁体   English

Delphi(VCL)泛型和数据绑定?

[英]Delphi (VCL) Generics and data binding?

Does anyone know if Delphi XE (I'm talking VCL here) has any Generic Collection classes that work with data-aware controls? 有没有人知道Delphi XE(我在这里说的是VCL)是否有任何使用数据感知控件的通用集合类? In other words, are there any Generic classes, like TObjectList<> that can be assigned to TDataSource.DataSet, or something similar? 换句话说,是否有任何通用类,如TObjectList <>可以分配给TDataSource.DataSet,或类似的东西?

Thanks. 谢谢。

Dan

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. 是的,您可以使用ObjectDataSet概念,我认为您最终必须基于链接的示例代码作为起始位置来实现自己。

The sample code shows how to fuse the concept of a regular non-generic TObjectList and a TDataSet. 示例代码显示了如何融合常规非泛型TObjectList和TDataSet的概念。 It uses RTTI to provide any list you wish to attach to it, of any object type. 它使用RTTI为任何对象类型提供您希望附加到其上的任何列表。 It uses RTTI and does not need to use Generics, rather it requires that you inherit from TPersistent. 它使用RTTI而不需要使用泛型,而是要求您继承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. 下一次,我将远离数据感知控件,只需使用虚拟控件(如VirtualTreeView和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. 它们都可以使用Generic Collection类,具有绑定功能 ,这使得将数据暴露给可视组件非常容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM