[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
(Under construction.)
procedure Rewrite (var F: any file; [FileName: String;] [BlockSize: Cardinal]); |
`Rewrite' opens a file for writing. If the file does not exist, it is created. The file pointer is positioned at the beginning of the file.
Like `Reset', `Append' and `Extend' do, `Rewrite' accepts an optional second and third parameter.
The second parameter can specify the name of the file in the filesystem. If it is omitted, the following alternative ways can be used to specify the name. There are so many different ways in order to be compatible to the idiosyncrasies of as many other Pascal compilers as possible. (If you know about yet other ways, let us know ...)
The following ways are only available if the file is external, i.e. a global variable which is mentioned in the program header. Otherwise, the file will be internal, i.e. get no name in the file system (it may get a name temporarily, but will then be erased automatically again). This is useful to store some data and read them back within a program without the need for permanent storage.
The last optional parameter determines the block size of the file. It is valid only for untyped files. Almost always, 1 is the most reasonable value here. However, the existence of this parameter is a BP compatibility feature, and in BP it defaults to 128 because of historic misdesign. Therefore, GPC requires this parameter to be present. In `--borland-pascal' mode, it makes it optional (like BP does), but warns about the strange default if omitted.
`Rewrite' is defined in ISO-7185 Pascal. The `BlockSize' parameter is a Borland Pascal extension. The `FileName' parameter is a GNU extension.
program RewriteDemo; var Sample: Text; begin Assign (Sample, 'sample.txt'); Rewrite (Sample); WriteLn (Sample, 'Hello, World!'); Close (Sample) end. |
section 9.18 Assign, section 9.227 Reset, section 9.11 Append, section 9.81 Extend, section 9.292 Update.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |