Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert any record to a string and back?

How can I convert any record type to a single String and back? Perhaps load the record into a stream and read it as a String? The records I'm using won't have any special types included - they're just using simple things like String, Integer, PChar, DWORD, and Array of [String], etc. and nothing like classes or functions.

This string will further be saved into various places, such as a flat text file, database record, sent over the network, etc. The string contents may be transferred by other means between each of these, such as copying the string from a text file and saving it to a database record. The general idea is that the string will be compatible enough to save anywhere, move it around, and load it back in to its original state. I do understand I need to be able to recognize what type of record it is and assign it accordingly, and that part I don't need help with.

like image 976
Jerry Dodge Avatar asked Jun 08 '12 22:06

Jerry Dodge


Video Answer


1 Answers

You can serialize your record using the RTTI, from here you can use XML, JSON or other format to persist the record data.

If you don't want write your own method to serialize the records try these alternatives.

  • superobject (using the TSuperRttiContext class you can serialize a record to JSON)
  • TKBDynamic
  • SynCommons unit from Synopse.
  • XmlSerial unit (Object and Record Serialization and De-serialization to XML) from Robert Love
like image 83
RRUZ Avatar answered Sep 29 '22 03:09

RRUZ