Files Delphi

Title: How to use TFileStream
type
TPerson = record
Name: string[50];
vorname: string[50];
end;
TComputer = record
Name: string[30];
cpu: string[30];
end;
var
Form1: TForm1;
Person: TPerson;
Computer: TComputer;
Stream: TFileStream;
implementation
{$R *.DFM}
//Save or create the file
procedure TForm1.Button1Click(Sender: TObject);
begin
try
Stream := TFileStream.Create('c:\test.dat', fmOpenReadWrite);
except
Stream := TFileStream.Create('c:\test.dat', fmCreate);
end;

//save 2 records for TPerson and TComputer
Person.Name := 'Grossenbacher';
Person.vorname := 'Simon';
Stream.WriteBuffer(Person, SizeOf(TPerson));
Person.Name := 'Stutz';
Person.vorname := 'Thomas';
Stream.WriteBuffer(Person, SizeOf(TPerson));
Computer.Name := 'Delphi';
Computer.cpu := 'Intel';
Stream.WriteBuffer(Computer, SizeOf(TComputer));
Computer.Name := 'Win';
Computer.cpu := 'AMD';
Stream.WriteBuffer(Computer, SizeOf(TComputer));
Stream.Free;
end;
//load records from TPerson to listbox1 and
//load records from TComputer to listbox2
procedure TForm1.Button2Click(Sender: TObject);
var
i: Integer;
begin
try

//open read only
Stream := TFileStream.Create('c:\test.dat', fmOpenRead);
except
ShowMessage('Datei konnte nicht geladen werden.');
Exit;
end;

//set variable i to the record count

//Read records TPerson
for i := 2 downto 1 do
begin
Stream.ReadBuffer(Person, SizeOf(TPerson));
Listbox1.Items.Add(Person.vorname + ' ' + Person.Name);
end;

//Read Records TComputer
for i := 2 downto 1 do
begin
Stream.ReadBuffer(Computer, SizeOf(TComputer));
Listbox2.Items.Add(Computer.Name + ' ' + Computer.cpu);
end;
Stream.Free;
end;