TFileStream

From Lazarus wiki
Revision as of 00:49, 26 August 2016 by Arent (talk | contribs) (Created page with "{{TFileStream}} A '''TFileStream''' is a descendant of TStream that get its data from a file on disk. A TFileStream reads entire file data into memory. {| class="wikit...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Deutsch (de) English (en) français (fr) polski (pl)

A TFileStream is a descendant of TStream that get its data from a file on disk. A TFileStream reads entire file data into memory.


Constant Decimal Description
fmCreate 65280 Creates a new file
fmOpenRead 0 opens a file for reading
fmOpenWrite 1 opens a file for writing
fmOpenReadWrite 2 opens a file for reading and writing
fmShareDenyWrite 32 prohibit writing if file is already opened


function readstream( fnam: string ): string;
var
  strm: TFileStream;
begin
  strm := TFileStream.Create( fnam, fmOpenRead or fmShareDenyWrite );
  try
    SetLength( readstream, strm.Size );
    dat.Read( readstream[1], strm.Size );
  finally
    FreeAndNil( strm );
  end;
end;


procedure writestream( fnam: string; txt: string );
var
  strm: TFileStream;
  n: longint;
begin
  strm := TFileStream.Create( fnam, fmCreate );
  n := Length( txt );
  try
    strm.Position := 0;
    strm.Write( txt[1], n );
  finally
    FreeAndNil( strm );
  end;
end;