File variables

Description

File variables are used to process files (i.e. create, destroy, change, or retrieve values from files). The term file is a shorthand way of saying collection of values defined by a file type.

The following built-in functions and procedures operate on file variables:

Most file variables are associated with buffer variables. File variables of type text are associated with buffer variables of type char. File variables of other types (except binary) are associated with buffer variables whose type is the same as the component type of the file variables type. File variables of type binary do not have a particular component type, and so they do not have buffer variables.

Example

The simple example program below uses a file variable (f) to create a file called numbers.dat and write the numbers 1 to 10 to the file.

program numbers;
var
   f : file of integer;
   i : integer;
begin
   assign(f, 'numbers.dat');
   rewrite(f);
   for i := 1 to 10 do
      write(f, i);
end.

Syntax

The syntax for referencing file variables is given below:

(NOTE: for clarity some parts of the syntax are omitted, see Irie Pascal Grammar for the full syntax):

   file-variable = variable-access