//自己动手做了个例子:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, 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;
aTRec =record //TRec不能做变量名
name: array[0..7]of char;
sex: array[0..1]of char;
age: integer;
resumesize:integer;
resume
ointer;
end;
TMyfile=file of aTRec;
var
Form1: TForm1;
f1:tmyfile;
f2:file;
buff:aTRec;
implementation
{$R *.DFM}
procedure readrecord(var f:file;var b:atrec);
begin
blockread(f,b.name,7);
blockread(f,b.sex,2);
blockread(f,b.age,sizeof(integer));
blockread(f,b.resumesize,sizeof(integer));
getmem(b.resume,buff.resumesize);
blockread(f,b.resume,b.resumesize);
end;
procedure writerecord(var f:file;b:atrec);
begin
blockwrite(f,b.name,7);
blockwrite(f,b.sex,2);
blockwrite(f,b.age,sizeof(integer));
blockwrite(f,b.resumesize,sizeof(integer));
blockwrite(f,b.resume,b.resumesize);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
assignfile(f2,'test.dat');
rewrite(f2,1);
getmem(buff.resume,10);
pchar(buff.resume):='1234567890';
buff.resumesize:=10;
buff.name:='1234567';
buff.sex:='12';
buff.age:=24;
writerecord(f2,buff);
closefile(f2);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
s
char;
begin
assignfile(f2,'test.dat');
reset(f2,1);
readrecord(f2,buff);
closefile(f2);
memo1.lines.add(buff.name);
memo1.lines.add(buff.sex);
memo1.lines.add(inttostr(buff.age));
memo1.lines.add(inttostr(buff.resumesize));
s:=buff.resume;
memo1.lines.add(strpas(s));
end;
end.