aik2
Programmer
- Jun 10, 2003
- 21
Hello All !
Please help, how to
put buffer from TFileStream.Read() into string?
Please help, how to
put buffer from TFileStream.Read() into string?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
procedure TForm1.ReadStreamClick(Sender: TObject);
const
Max = 1024;
var
stream: TFileStream;
buffer: pchar;
begin
stream := TFileStream.Create ( FileName, fmOpenRead );
try
GetMem ( buffer, Max );
try
stream.read ( buffer^, Max );
Edit1.Text := StrPas ( buffer );
finally
FreeMem ( buffer );
end;
finally
stream.free;
end;
end;
procedure TForm1.ReadStreamClick(Sender: TObject);
const
MaxLen = 1024;
var
buffer: string;
stream: TFileStream;
begin
SetLength ( buffer, MaxLen );
stream := TFileStream.Create ( YourFileName, MaxLen );
try
stream.read ( pchar(buffer)^, MaxLen );
Edit1.Text := buffer;
finally
stream.free;
end;
end;
with TFileStream.Create(AFileName, fmOpenRead) do
try
SetLength(AString, Size);
Read(PChar(AString)^, Size);
finally
Free;
end;