views:

1280

answers:

6

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

+4  A: 

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.

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

Tim Jarvis
+1  A: 

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.

skamradt
+2  A: 

I use the TI Object persistence framework (tiopf.com). I wrote the overview at 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.

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

SeanX
+2  A: 

You also can use the famous hibernate know from java.

the delphi port you can find here: dHibernate

Bernd Ott
A: 

how did you develop this application. can you give some idea about it.. I mean even i want to develop an application where i make use of TDrawGrid control. i ll loading a bitmap on the canvas of the grid cell. i should be able to draw line on to the image, select the line, move the line and delete it as well. You have any idea how to achieve this.

I did't have idea too, then i started to write classes like Point, Line, Arc etc.,then Collections for those classes etc. You'll probobly need to inherit all classes from base class that have methods like Draw,HitTest.For drawing just use control that has published Canvas prop i think its PaintBox.
Edin
+1  A: 

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

p.s. http://www.delphi3000.com/ seems to be blacklisted (attacking web site alarm)

mjustin
Delphi 2010 has added few units for JSON and Datasnap, but you can them without datasnap.
Mohammed Nasman