Contents | Prev | Next
7.4.35 The open procedure
Description
The open procedure associates a file variable
with a file (i.e. opens the file variable and allows it to
be used to manipulate the file). The open procedure can open the file variable
in read-only mode,
write-only mode,
read/write mode, or
append mode.
Parameters
- The first parameter is a reference to the file variable
to be opened.
- The second parameter is an expression of
string type or char type,
and names the file variable, referenced by the
first parameter, as if the built-in procedure assign
had been called.
- The third parameter is an expression of
integral type which specifies the mode the
file variable should be opened in. The
file mode constants can be used to specify the mode. The
readmode and
writemode constants can be
added or
OR'd together to specify that the
file variable be opened in read/write mode (i.e. for both
reading and writing).
The name of the file variable, referenced by the first parmater,
controls which file is opened by the open procedure. If the name is a non-empty
string then a file with that name is opened. If the name is an empty string then the file
opened is either the standard output file, or a temporary file (with a system generated name),
depending on the project options set when the program was compiled.
File variables can get named in the
following ways:
Example
open(f, 'filename', readmode); //this is the same as reset(f, 'filename');
open(f, 'filename', writemode); //this is the same as rewrite(f, 'filename');
open(f, 'filename', appendmode); //this is the same as append(f, 'filename');
The following call to open
open(f, 'test.txt', readmode+writemode);
will open the file 'test.txt in read/write mode (i.e. for both reading and writing).
Portability
Operating Systems: All
Standard Pascal: No
Contents | Prev | Next