以前,为了保存某些应用程序的设置,我使用了:
TSettings = class(TPersistent)但是现在,我在TSettings类中使用TObjectList作为属性。
因此,我放弃了TCollection/TCollection in,以支持Generics .
在序列化它时,没有项目列表.我认为这是因为TObjectList不是来自TPersistent。
如何用TJvAppXMLFileStorage序列化我的TJvAppXMLFileStorage?
发布于 2012-09-21 07:29:46
通过调用JvAppXMLFileStorage.WriteList,我成功地用几行代码序列化了我的泛型列表。
首先,这是序列化列表的方式。下面将详细介绍WriteGenericsObjectListItem<TMyClass>方法。
JvAppXMLFileStorage.WriteList('mylist',TObject(MyGenericList), MyGenericList.Count, WriteGenericsObjectListItem<TMyClass>);然后,我只需要定义--如何序列化泛型列表中的每个项。为此,我创建了一个通用方法:
procedure TMySerializer.WriteGenericsObjectListItem<T>(Sender: TJvCustomAppStorage;
const Path: string; const List: TObject; const Index: Integer; const ItemName: string);
begin
if(List is TObjectList<T>) then
if Assigned(TObjectList<T>(List)[Index]) then
Sender.WritePersistent(Sender.ConcatPaths([Path, Sender.ItemNameIndexPath (ItemName, Index)]), TPersistent(TObjectList<T>(List)[Index]));
end;就这样!
我没有修改JCL/JVCL代码,只将这些代码添加到我的程序中。
我想我将向JCL/JVCL团队提交一个补丁,以添加与所有Generics容器的兼容性。
我希望这能帮到你!
https://stackoverflow.com/questions/12462029
复制相似问题