保存/加载 TObject(TPercient) 到 XML
大家。
我正在尝试
TA= class(TPersistent)
private
FItems: TObjectList<TB>;
FOnChanged: TNotifyEvent;
public
constructor Create;
destructor Destroy; override;
...
procedure Delete(Index: Integer);
procedure Clear;
procedure SaveToFile(const FileName: string);
...
property OnChanged: TNotifyEvent read FOnChanged write FOnChanged;
end;
使用以下代码将我的类保存到文件:
var
Storage: TJvAppXMLFileStorage;
begin
Storage := TJvAppXMLFileStorage.Create(nil);
try
Storage.WritePersistent('', Self);
Storage.Xml.SaveToFile(FileName);
finally
Storage.Free;
end;
但文件始终为空。
我做错了什么?
everybody.
I'm trying to save my class:
TA= class(TPersistent)
private
FItems: TObjectList<TB>;
FOnChanged: TNotifyEvent;
public
constructor Create;
destructor Destroy; override;
...
procedure Delete(Index: Integer);
procedure Clear;
procedure SaveToFile(const FileName: string);
...
property OnChanged: TNotifyEvent read FOnChanged write FOnChanged;
end;
to file using the following code:
var
Storage: TJvAppXMLFileStorage;
begin
Storage := TJvAppXMLFileStorage.Create(nil);
try
Storage.WritePersistent('', Self);
Storage.Xml.SaveToFile(FileName);
finally
Storage.Free;
end;
but file is always empty.
What am I doing the wrong way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来 TJvCustomAppStorage 不支持属性中的泛型。该代码没有使用扩展 RTTI,并且对 TJvCustomAppStorage.GetPropCount 的调用返回 0。
这导致了另一个问题 - 是否有支持泛型的 Delphi 对象序列化库??
我的测试代码:
It looks like TJvCustomAppStorage does not support Generics in properties. The code makes no use of extended RTTI and the call to TJvCustomAppStorage.GetPropCount returns 0.
This leads to another question - Are there Delphi object serialization libraries with support for Generics??
My test code:
我不确定,但如果 TJvAppXMLFileStorage 使用 RTTI 那么我认为您必须发布要保存/加载的属性。
I'm not sure but if TJvAppXMLFileStorage uses RTTI then I think you have to publish the properties that you want to save / load.