Delphi对象持久化,最好的方法是什么

时间:2022-09-15 20:43:07

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.

我已经开发了绘制一些形状(大多数是线条)的应用程序,现在我需要能够将草图存储到文件中,我知道delphi已经构建了对象持久性的例程,但我从未使用它。

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.

有人告诉我可以使用对象持久性,如果我必须持久化对象也引用其他对象(将被存储到),我有TLine对象可以连接到其他TLine对象等。

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

是否更好地使用此功能或编写自定义过程来存储/读取文件对象。

thx

6 个解决方案

#1


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).

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

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 Jedi项目中有一些例程可以为你处理组件流,但我还没有直接使用它们,因为我的大部分XML流都是手工完成的,因为我的对象非常简单,只能用一个少数几处房产。

#2


The built in object persistance is primarily designed for use in streaming components to a dfm, the work that you would need to do to persist your sketch would not benefit very much from that mechanism.

内置对象持久性主要用于将组件流式传输到dfm,为了保持草图而需要做的工作不会从该机制中受益很多。

I think that you would be better off coming up with a custom scheme.

我认为你最好提出一个自定义方案。

#3


I use the TI Object persistence framework (tiopf.com). I wrote the overview at http://tiopf.sourceforge.net/Doc/overview/index.shtml.

我使用TI对象持久性框架(tiopf.com)。我在http://tiopf.sourceforge.net/Doc/overview/index.shtml上写了概述。

It will let you save objects and lists to xml, csv, databases etc. It handles child objects automatically.

它将允许您将对象和列表保存到xml,csv,数据库等。它自动处理子对象。

If you are interested, use the svn version, not the sourceforge download as it has more features (inc partial D 2009 support).

如果您有兴趣,请使用svn版本,而不是sourceforge下载,因为它具有更多功能(包括部分D 2009支持)。

#4


You also can use the famous hibernate know from java.

您也可以使用java中知名的hibernate。

the delphi port you can find here: dHibernate

您可以在这里找到delphi端口:dHibernate

#5


JSON is a new and very compact way to store objects. Two libraries are available for Delphi: SuperObject and lkJSON.

JSON是一种新的,非常紧凑的存储对象的方法。 Delphi有两个库:SuperObject和lkJSON。

#6


With NativeXML from http://www.simdesign.nl/xml.html I accomplished to read/write delphi in-memory objects from/to XML code. Very nice, very easy, with demo included here: http://www.simdesign.nl/forum/download/file.php?id=236

使用来自http://www.simdesign.nl/xml.html的NativeXML,我完成了从/向XML代码读取/写入delphi内存中对象。非常好,非常简单,此处包含演示:http://www.simdesign.nl/forum/download/file.php?id = 236

#1


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).

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

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 Jedi项目中有一些例程可以为你处理组件流,但我还没有直接使用它们,因为我的大部分XML流都是手工完成的,因为我的对象非常简单,只能用一个少数几处房产。

#2


The built in object persistance is primarily designed for use in streaming components to a dfm, the work that you would need to do to persist your sketch would not benefit very much from that mechanism.

内置对象持久性主要用于将组件流式传输到dfm,为了保持草图而需要做的工作不会从该机制中受益很多。

I think that you would be better off coming up with a custom scheme.

我认为你最好提出一个自定义方案。

#3


I use the TI Object persistence framework (tiopf.com). I wrote the overview at http://tiopf.sourceforge.net/Doc/overview/index.shtml.

我使用TI对象持久性框架(tiopf.com)。我在http://tiopf.sourceforge.net/Doc/overview/index.shtml上写了概述。

It will let you save objects and lists to xml, csv, databases etc. It handles child objects automatically.

它将允许您将对象和列表保存到xml,csv,数据库等。它自动处理子对象。

If you are interested, use the svn version, not the sourceforge download as it has more features (inc partial D 2009 support).

如果您有兴趣,请使用svn版本,而不是sourceforge下载,因为它具有更多功能(包括部分D 2009支持)。

#4


You also can use the famous hibernate know from java.

您也可以使用java中知名的hibernate。

the delphi port you can find here: dHibernate

您可以在这里找到delphi端口:dHibernate

#5


JSON is a new and very compact way to store objects. Two libraries are available for Delphi: SuperObject and lkJSON.

JSON是一种新的,非常紧凑的存储对象的方法。 Delphi有两个库:SuperObject和lkJSON。

#6


With NativeXML from http://www.simdesign.nl/xml.html I accomplished to read/write delphi in-memory objects from/to XML code. Very nice, very easy, with demo included here: http://www.simdesign.nl/forum/download/file.php?id=236

使用来自http://www.simdesign.nl/xml.html的NativeXML,我完成了从/向XML代码读取/写入delphi内存中对象。非常好,非常简单,此处包含演示:http://www.simdesign.nl/forum/download/file.php?id = 236