4
435214
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;type a=packed record num:integer; adr:array of integer; //动态数组 end;var FStr: TFileStream; X: a; var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var i:integer;begin FStr:=TFileStream.Create('E:/abc.dat', fmCreate);//生成文件 SetLength(x.adr, 9); //定义数组的长度 for i:=1 to 9 do x.adr:=i; x.num:=9; try FStr.Write(x, sizeof(x)); //写入文件 finally FStr.Free; end;end;procedure TForm1.Button2Click(Sender: TObject);var i:integer;begin FStr:=TFileStream.Create('E:/abc.dat', fmopenread); for i:=1 to x.num do memo1.Lines.Add(inttostr(x.adr)); Fstr.free;end;end.