Warum schreibst du auch alles einzeln rein?
Delphi-Quellcode:
type
TFoo = record
Name: String[25];
ID: Integer;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
fs: TFileStream;
Foo: TFoo;
begin
fs := TFileStream.Create('d:\test.dat', fmCreate);
try
Foo.Name := 'Müller';
Foo.ID := 666;
fs.WriteBuffer(Foo, sizeof(TFoo));
finally
FreeAndNil(fs);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
fs: TFileStream;
Foo: TFoo;
begin
fs := TFileStream.Create('d:\test.dat', fmOpenRead);
try
fs.ReadBuffer(Foo, sizeof(TFoo));
ShowMessage(Foo.Name+', '+IntToStr(Foo.ID));
finally
FreeAndNil(fs);
end;
end;