const
anzahl = 12;
datei = 'C:\TEST.TXT';
a: array[0..anzahl - 1] of byte = (68, 66, 82, 46, 83, 111, 102, 116, 119,
97, 114, 101);
var
f: file of byte;
s: string;
procedure TForm1.FormCreate(Sender: TObject);
begin
assignfile(f, datei);
end;
function bytesschreiben: boolean;
var
x: byte;
begin
result := false;
{$I-}
reset(f);
if ioresult = 0 then begin
try
seek(f, filesize(f));
for x := 0 to anzahl - 1 do write(f, a[x]);
result := true;
finally
closefile(f);
end;
end;
{$I+}
end;
function byteslesen: boolean;
var x: byte;
begin
result := false;
{$I-}
fillchar(a, sizeof(a), 0);
reset(f);
if ioresult = 0 then begin
try
if filesize(f) >= anzahl then begin
seek(f, filesize(f) - anzahl);
for x := 0 to anzahl - 1 do read(f, a[x]);
result := true;
end;
finally
closefile(f);
end;
end;
{$I+}
end;
function bytesabschneiden: boolean;
begin
result := false;
{$I-}
reset(f);
if ioresult = 0 then begin
try
if filesize(f) >= anzahl then begin
seek(f, filesize(f) - anzahl);
truncate(f);
result := true;
end;
finally
closefile(f);
end;
end;
{$I+}
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
if not bytesschreiben then s := 'FEHLER'
else s := 'O.K.';
showmessage(s);
end;
procedure TForm1.Button6Click(Sender: TObject);
var x: integer;
begin
if not byteslesen then s := 'FEHLER' else
begin
s := '';
for x := 0 to anzahl - 1 do s := s + char(a[x]); // z.B.
end;
showmessage(s);
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
if not bytesabschneiden then s := 'FEHLER'
else s := 'O.K.';
showmessage(s);
end;