From Appmethod Libraries
Jump to: navigation, search

Object Pascal

procedure Rewrite(var F: File; [ RecSize: Integer]); overload;
procedure Rewrite(var F: File; [ RecSize: Integer]); overload;


Type Visibility Source Unit Parent
procedure public System.pas System System


Creates a new file and opens it.

In Object Pascal code, Rewrite creates a new external file with the name assigned to F.

F is a variable of any file type associated with an external file using AssignFile. RecSize is an optional expression that can be specified only if F is an untyped file. If F is an untyped file, RecSize specifies the record size to be used in data transfers. If RecSize is omitted, a default record size of 128 bytes is assumed. If <RecSize> is equal to or lower than 0, it causes a 106 I/O Error.

If an external file with the same name already exists, it is deleted and a new empty file is created in its place.

If F is already open, it is first closed and then re-created. The current file position is set to the beginning of the empty file.

If F was assigned an empty name such as AssignFile(F, ''), then after the call to Rewrite, F refers to the standard output file.

After calling Rewrite, Eof(F) is always True.

If any I/O error happens, Rewrite closes the file. You do not need to call CloseFile.

Note: {$I+} handles run-time errors using exceptions. When using {$I-}, use IOResult to check for I/O errors.

See Also

Code Examples