这个代码是测试过的,完全符合你的要求:
=========================================================
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
Taa = record
ntime : Tdatetime;
s : string[3];
end;
Taaaaa = record
pp : string[4];
cc : array[0..10] of Taa;
end;
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
arraytemp : array of Taaaaa;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
m: TMemorystream;
begin
setlength(arraytemp,2);
arraytemp[0].pp := 'ppp';
arraytemp[0].cc[0].s:='1.3';
m:=TMemorystream.Create;
m.Write(arraytemp[0],2*sizeof(arraytemp[0]));//向流中写入内容
m.SaveToFile('c:/temp.dat');//保存到文件里
m.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
m: TMemorystream;
begin
SetLength(arraytemp,2);
m:=TMemorystream.Create;
m.LoadFromFile('c:/temp.dat'); //从文件里读
m.ReadBuffer(arraytemp[0],2*sizeof(arraytemp[0])); //向rec中写入内容
m.Free;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
showmessage(arraytemp[0].pp);
showmessage(arraytemp[0].cc[0].s);
end;
end.