This is a function I use...
function ReadString(var aStream: TFileStream): String;
var
lInt: Integer;
lStr: String;
begin
result := '';
aStream.read(lInt, SizeOf(lInt));
SetString(lstr, nil, lInt);
aStream.read(Pointer(lStr)^, lInt);
result := lStr;
end;
Note that it reads an integer to get the size of the next string to read.
Therefore my file format would be
10Thisstring2hi etc...
Just replace lint with 1024 and eliminate the first read call.
works for me!
JED
--------------------------------------------------------------------------------------------------------->
OK this is my code so far
var
FSize : LongInt;
TextFile : TFileStream;
Buffer : PChar;
var X:longint;
begin
GetMem(Buffer,1024);
try
TextFile := TFileStream.Create(ParamStr(1),fmOpenRead or
fmShareDenyNone);
FSize := TextFile.Size;
ShowMessage(IntToStr(FSize)); {
if (FSize > 1024) then begin
TextFile.Seek(-1024,soFromEnd);
end; }
LogField.Lines.Clear;
X := TextFile.Read(Buffer,1024);
ShowMessage(IntToStr(X));
LogField.Text := String(Buffer);
TextFile.Free;
except
LogField.Lines.Add('Error opening file');
end;
end;
Except that the file length is something like 19576 and the value of X
comes
as 0. This is with no seeking so it should read from the start.
How do you define Buffer since it obviously doesn't like the declaration.
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz