在 Delphi 中如何将动态数组保存到 FileStream?
我在 Delphi 2009 中有以下结构:
type
IndiReportIndi = record
IndiName: string;
NameNum: integer;
ReportIndiName: string;
end;
var
XRefList: array of IndiReportIndi;
其中 XRefList 是动态数组。
我想将 XRefList 保存到 FileStream。我该如何做到这一点并包含所有 IndiName 和 ReportIndiName 字符串,以便稍后从该 FileStream 加载时可以再次检索它们?
I have the following structures in Delphi 2009:
type
IndiReportIndi = record
IndiName: string;
NameNum: integer;
ReportIndiName: string;
end;
var
XRefList: array of IndiReportIndi;
where XRefList is a dynamic array.
I want to save XRefList to a FileStream. How do I do that AND include all the IndiName and ReportIndiName strings so that they will all be retrievable again when I later load from that FileStream?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用:http://code.google.com/p/kblib/
保存整个 XRefList流式传输使用:
加载回来:
Use: http://code.google.com/p/kblib/
To save whole XRefList to stream use:
To load it back:
要读取这些数据,您可以使用 TReader 和 ReadInteger/ReadString。
To read those data you use a TReader and ReadInteger/ReadString.
简单的 TFileStreamEx 保存变量
http://forum.chertenok.ru/viewtopic.php?t= 4642
从2005年开始就和他们一起工作,没有任何问题......
Simple TFileStreamEx to save variables
http://forum.chertenok.ru/viewtopic.php?t=4642
Work with them from 2005th year, without any problems...
只是为了准确的答案:
考虑看看
TDynArray
包装器,它能够将任何记录序列化为二进制,也可以与动态数组进行序列化。有很多类似
TList
的方法,包括新方法(例如散列或二分搜索)。针对速度和磁盘使用进行了非常优化,适用于 Delphi 5 至 XE2 - 和开源。
另请参阅如何在 TList 中存储动态数组?
Just for the answer to be accurate:
Consider taking a look at the
TDynArray
wrapper, which is able to serialize any record into binary, and also to/from dynamic arrays.There are a lot of
TList
-like methods, including new methods (like hashing or binary search).Very optimized for speed and disk use, works for Delphi 5 up to XE2 - and Open Source.
See also How to store dynamic arrays in a TList?