next up previous contents index
Next: Rmdir Up: Functions and Procedures Previous: Reset

Rewrite

   

Declaration:

Procedure Rewrite (Var F : Any File Type[; L : longint]) ;

Description:

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.

Errors:

If the file cannot be opened for writing, then a run-time error is generated. This behavior can be changed by the {$i} compiler switch.

See also:

Reset, Assign, Close

Example
Program Example52;

{ Program to demonstrate the Rewrite function. }

Var F : File;
    I : longint;

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



Michael Van Canneyt
Thu Sep 10 14:02:43 CEST 1998