编写复杂的记录到文件 [英] Writing complex records to file

查看:137
本文介绍了编写复杂的记录到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我已经定义在我的项目的一些记录可包括其他记录,也正常的数据类型和其他记录的动态数组,
它是N实例记录类型

Hi I have defined some records in my project which may be consisted of other records and also dynamic arrays of normal data types and other records , it is n example of a record type

  Type1=record
    x:integer;
  end;
  Type2=record
    Y:array of X;
    str:string;
  end;

当我试图挽救这些记录类型的变量,像这样BlockWrite命令功能到文件之一:

When I tried to save one of variables of these records type to file with blockwrite function like this :

var
  Temp1:Type2;
  begin
    setlength(temp1.y,100);
    blockwrite(MyFile,Temp1,sizeOf(Temp1);

这只是写不亚于纯记录的大小,但temp1中具有被调整大小的对动态数组,
可能有人请告诉我怎么可以写一个复杂的记录到文件中,我的意思是像什么VB6中使用。
谢谢

it just wrote as much as the size of pure record is ,but temp1 has a dynmic arrays which is resized , Could someone please tell me how I can write a complex record to a file , I mean something like what is used in VB6 . Thanks

推荐答案

您可以使用的http:// kblib 。谷歌code.com (任意动态记录,还记录了一个包含其他记录等工作)。测试在德尔福2009分之2006/ XE(它不使用在D2010引入了扩展RTTI)。无需编写保存/加载$ C $手动C(只有一行保存/载入任何动态类型 - 字符串,记录,动态数组)。

You can use http://kblib.googlecode.com (works with any dynamic records, also records that contains other records, etc.). Tested on Delphi 2006/2009/XE (it doesn't use extended RTTI introduced in D2010). No need to write save/load code manually (just one line to save/load any dynamic type - strings, records, dynamic arrays).

在你的榜样,这将是某事。像这样的:

In your example it would be sth. like this:

TKBDynamic.WriteTo(lStream, lType2, TypeInfo(Type2));

要载入它:

TKBDynamic.ReadFrom(lStream, lType2, TypeInfo(Type2));

如果有人有兴趣如何应对记录版本,只是张贴新的问题,然后我会写一些例子。

If anyone is interested how to deal with 'record versions', just post new issue and then I'll write some examples.

相似questsion:

Similar questsion:

  • How Can I Save a Dynamic Array to a FileStream in Delphi?
  • Delphi 2010: How to save a whole record to a file?

这篇关于编写复杂的记录到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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