将任何记录转换为字符串并返回? [英] Convert any record to a string and back?
问题描述
如何将任何记录
类型转换为单个 String
并返回?也许将记录加载到流中,并将其作为String读取?我使用的记录不会包含任何特殊类型 - 它们只是使用简单的东西,如 String
,整数
, PChar
, DWORD
和 [String]的数组
等等,没有什么像类或功能。
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.
推荐答案
您可以使用RTTI序列化您的记录,从这里可以使用XML,JSON或其他格式来持久记录数据。
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.
- 超级对象(使用TSuperRttiContext类可以将记录序列化为JSON) / li>
- TKBDynamic
- SynCommons 单元。
- XmlSerial 单元(Object and Record Serialization and De-serialization to XML)from Robert Love
- 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
这篇关于将任何记录转换为字符串并返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!