Unit 'System' Package
[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] [#rtl]


Open file for writing.


Source position: systemh.inc line 1417

procedure Rewrite(

  var f: file;

  l: LongInt


procedure Rewrite(

  var f: file


procedure Rewrite(

  var f: TypedFile


procedure Rewrite(

  var t: Text



Rewrite opens a file F for writing. F can be any file type. If F is an untyped or typed file, then it is opened for reading and writing. If F is an untyped file, the record size can be specified in the optional parameter L. Default a value of 128 is used. if Rewrite finds a file with the same name as F, this file is truncated to length 0. If it doesn't find such a file, a new file is created.

Contrary to Turbo Pascal, Free Pascal opens the file with mode fmoutput. If it should be opened in fminout mode, an extra call to Reset is needed.

File sharing is not taken into account when calling Rewrite.

Note that the path can be only 255 characters long.


Depending on the state of the {$I} switch, a runtime error can be generated if there is an error. In the {$I-} state, use IOResult to check for errors.

See also



Open file for reading.



Assign a name to a file.



Close a file.



Write file buffers to disk.



Open a file in append mode.


Program Example52;

{ Program to demonstrate the Rewrite function. }

Var F : File;
    I : longint;

  Assign (F,'Test.tmp');
  { Create the file. Recordsize is 4 }
  Rewrite (F,Sizeof(I));
  or:=1 to 10 do
    BlockWrite (F,I,1);
  close (f);
  { F contains now a binary representation of
    10 longints going from 1 to 10 }

Documentation generated on: Jul 19 2024