In Java, one can save a serializable object to a file and load an object from that file. Can we do this in Delphi? If yes, How?
-
2In Java it is not possible for any object: the object's class must declare that it implements Serializable (but that's all, it is only a tagging interface wihtout any methods). The nice thing is that Java serializes all object attributes by default, regardless of their access modifier (no "DIY" RTTI coding is required). – mjn Sep 20 '10 at 10:20
-
already edited my question – rajeemcariazo May 15 '13 at 10:57
4 Answers
If you ask "Can we do this in Delphi?" - the answer is: yes. I guess you want to know, HOW this can be done in Delphi? Well this depends on what do you want to serialize:
If you want to serialize
- your own data objects, then you could write your own saveTo/loadFrom functions
- components, then you could use the built-in component streaming system
- any unknown object, then you need some RTTI techniques and the objects must publish their serializable properties

- 13,037
- 1
- 44
- 67
-
3Published visibility is only needed when still using the "old style" RTTI. As of D2010 the extended RTTI does not require properties to have published visibility in order to be able to enumerate them. Plus it can enumerate a lot more than "just" properties. – Marjan Venema Sep 21 '10 at 06:23
The first article linked to by Andre seems (maybe I skimmed to fast) to use the "old" pre-D2010 style RTTI (Run-Time Type Information), which is dependent on properties having published visibility in order to be able to enumerate them.
As of D2010 Delphi has a completely new extended RTTI (built on top of the old one) which does not require published visibility and does a lot more than enumerate properties. DeHL, as described in the second article linked to be Andre, does use the new RTTI, and if you are looking for a library, I would also recommend this library.
If you prefer to build your own, you could have a look at an article on XML-serialization using the new RTTI by Robert Love: http://robstechcorner.blogspot.com/2009/10/xml-serialization-basic-usage.html
Robert Love also has a nice overview of RTTI articles: http://robstechcorner.blogspot.com/2009/09/so-what-is-rtti-rtti-is-acronym-for-run.html
And for some more ideas on what can be done with the new style RTTI, have a look at
Practical usage for Delphi's new RTTI - Attributes,Values and Why should I care about RTTI in Delphi?

- 1
- 1

- 19,136
- 6
- 65
- 79
NativeXML NativeXML website has the ability to store/retrieve objects in an XML format, which gives you additional manipulation capability over the RTTI methodology. Fast and easy manipulation of XML documents and the added capability of saving/loading persistent objects.

- 530
- 4
- 17