Delphi对象持久化,最好的方法是什么 [英] Delphi object persistence, what is the best way

查看:141
本文介绍了Delphi对象持久化,最好的方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了绘制一些形状的应用程序(主要是线条),现在我需要能够将草图存储到文件中,我知道delphi已经建立了用于对象持久化的例程,但是我从来没有使用过。有人可以告诉我可以使用对象持久性,如果我必须持久化对象,并引用其他对象(将被存储到),我有TLine对象可以连接到其他TLine对象等。



最好使用此功能或编写自定义过程来存储/读取对象到/从文件。



thx

解决方案

过去使用的一种方法是存储我的对象编写一个XML文件中的属性,编写一个添加到传递的IXMLNode的自定义保存例程,以及一个从传递的IXMLNode读取的新构造函数。我将组件存储为一个节点,属性作为属性(除非属性是另一个对象,那么它将是一个子节点)。



我相信有一些例程在Delphi Jedi项目中,它将为您处理组件流,但是我没有直接使用它们,因为我的XML流已经完成了,因为我的对象非常简单,只能使用少量属性渲染。 p>

I have developed application for drawing some shapes (lines mostly) , now i need to be able to store sketch to a file, i know that delphi has build in routines for object persistance, but i have never used it.

Can someone tell me can object persistence be used if i have to persist object that have also references to other objects (that will be stored to), i have TLine object wich can be connected to other TLine object etc.

Is it better to use this feature or write custom procedure to store/read object to/from file.

thx

解决方案

One method that I have used in the past is to store my object properties in an XML file writing a custom "save" routine which adds to a passed IXMLNode, and a new constructor which reads from a passed IXMLNode. I store component as a node, and the properties as attributes (unless the property is another object, then it would be a child node).

I believe there are some routines in the Delphi Jedi project which will handle component streaming for you, but I have not used them directly as most of my XML streaming has been done by hand since my objects were extremely simple and could be rendered with only a handful of properties.

这篇关于Delphi对象持久化,最好的方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆