Re: Writing Binary Files with TFileStream



Correction on the WRITE function:

var
FS : TFileStream;
i : Integer;
l : LongInt;
x, e : Word;
brwFieldID, brwValue : String;
begin
try
if FileExists(fname) then
FS := TFileStream.Create(fname, fmOpenWrite)
else
FS := TFileStream.Create(fname, fmCreate);
for i := 0 to tData.Count - 1 do
begin
brwFieldID := tData.Names[i];
brwValue := tData.ValueFromIndex[i];
x := StrToInt(brwFieldID);
FS.Write(x, SizeOf(x));
l := length(brwValue);
FS.Write(l, SizeOf(l));
FS.Write(brwValue[1], l);
end;
e := $FFFF;
FS.Write(e, SizeOf(e));
FS.Free;
result := True;
except
result := False;
end;

.