有谁知道与泛型和 RTTI 一起使用的 TDataset 后代,以便我可以编写这样的代码,并在 GUI 中使用数据感知组件? :
...
ds:TDataset<TPerson>;
...
procedure DoStuff;
begin
ds:=TDataset<TPerson>.create;
ds.add(TPerson.Create('A.','Hitler',77));
ds.add(TPerson.Create('O.','Bin Laden',88));
end;
This should有可能。可以通过 RTTI 创建 fielddef,因为数据的确切类型是已知的。值还可以自动来回整理,因此您可以查看和编辑类或记录中的数据。
我讨厌编写大量无用的编组代码,而所需的信息已经可以通过 RTTI 获得。
或者也许有人曾经编写过某种 TEnumerable TDataset 适配器?
是否存在类似的东西,或者我应该开始写一个?
...
The closest thing that I could find is an (excellent!) example http://etutorials.org/Programming/mastering+delphi+7/Part+III+Delphi+Database-Oriented+Architectures/Chapter+17+Writing+Database+Components/A+Dataset+of+Objects/ by Marco Cantu, from Mastering Delphi 7, but the code itself doesn't make use of new language features like generics, the new RTTI system, or attributes, and it doesn't work with Unicode delphi. TDataset has changed since D7 too.