且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将TObject保存到文件

更新时间:2022-05-09 21:36:20

如上所述,最简单的方法是使用及其 WriteComponent ReadComponent 方法。

请注意

- 它对TComponent 的后代有效,而不是纯TObject;

- 只有已发布的属性(保存在dfm中的那些),而不是公开的,而不是更贵的;

- 恢复组件时,您必须特别注意Name属性

As already stated, the easiest way is to use a Stream and its WriteComponent and ReadComponent methods.
But be aware that :
- it works for descendants of TComponent, not plain TObject;
- only for the published properties (those saved in a dfm), not the public ones nor (a fortiori) the privwte ones;
- you have to pay a special attention for the Name property when restoring the component.

您可能会在这些SO答案中找到一些代码:在Delphi中运行时替换可视化组件运行时复制组件

You may find some code you could use in these SO answers: Replace visual component at runtime in Delphi, Duplicating components at Run-Time