Contents | Prev | Next

6.5 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 a buffer variable as described in the next section.

Buffer Variables

Most file variables have an associated buffer variable, which provides direct access to the next value waiting to be read from the file, and/or the next value to be stored to the file. Buffer variables are created and destroyed when their associated file variables are created and destroyed.

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 file variables' component 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 buffer variables is given below:

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

   buffer-variable = file-variable '^' | file-variable '@'

Where file-variable is a reference to a file variable.

Contents | Prev | Next