将任何记录转换为字符串并返回? [英] Convert any record to a string and back?

查看:173
本文介绍了将任何记录转换为字符串并返回?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将任何记录类型转换为单个 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.

  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆