Delphi XE/RTTI user object serialization Given a basic class like below, I've seen some references of the ability to serialize user objects using the latest RTTI methods that are in the later versions of Delphi.
![]()
Another solution, working from Delphi 5 up to XE2, is available.In fact, it implements:. Some low-level RTTI functions for handling record types: RecordEquals, RecordSave, RecordSaveLength, RecordLoad;. A dedicated TDynArray object, which is a wrapper around any dynamic array, able to expose TList-like methods around any dynamic array, even containing records, strings, or other dynamic arrays.
It's able to serialize any dynamic array.Serialization uses an optimized binary format, and is able to save and load any record or dynamic array as RawByteString. You have also JSON serialization at hand, including custom layout - see.
JVCL is one choice, but if you prefer a small, self-contained library, there's OmniXML (Mozilla Public License 1.1, ). I've used it successfully in several projects, and I find it the simplest XML library to use in Delphi.
![]()
OmniXML comes with 'OmniXMLPersistent' unit, which does what you need via RTTI, just like the JVCL solution does. // saving:pers: TPersistent;// SaveToFile is a class method, so no need to instantiate the object:TOmniXMLWriter.SaveToFile( pers, 'd:pathfile.xml', pfAttributes, ofIndent );pfAttributes means properties will be stored as attributes of XML elements; ofIndent will produce a nicely indented code for readability. // loading:TOmniXMLWriter.LoadFromFile( pers, 'd:pathfile.xml' ).
![]() Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |