procedure TForm1.Button1Click(Sender: TObject); var Buffer: PChar; Stream: TFileStream; Size: LongInt; begin Stream := TFileStream.Create('Unit1.pas', fmOpenRead); try Size := Stream.Size; GetMem(Buffer, Size); try Stream.Read(Buffer[0], Size); Memo1.Lines.Text := Buffer; finally FreeMem(Buffer); end; finally Stream.Free; end; end;
или не используя управление памятью:
procedure TForm1.Button2Click(Sender: TObject); var Buffer: string; Stream: TFileStream; begin Stream := TFileStream.Create('unit1.pas', fmOpenRead); try SetLength(buffer, Stream.Size); Stream.Read(Buffer[1], Stream.Size); Memo1.Lines.Text := Buffer; finally Stream.Free; end; end;