File Types
A file a sequence of elements of the same type. Standard I/O routines use the predefined
TextFile
or
Text
type,
which represents a file containing characters organized into lines. For more information about file input and output,
see Standard routines and I/O.
To declare a file type, use the syntax
type fileTypeName
=
fileoftype
where fileTypeName is any valid identifier and type is a fixed-size type. Pointer types - whether implicit or explicit -
are not allowed, so a file cannot contain dynamic arrays, long strings, classes, objects, pointers, variants, other files,
or structured types that contain any of these.
For example,
type
PhoneEntry = record
FirstName, LastName: string[20];
PhoneNumber: string[15];
Listed: Boolean;
end;
PhoneList = file of PhoneEntry;
85
declares a file type for recording names and telephone numbers.
You can also use the
file of ...
construction directly in a variable declaration. For example,
var List1: file of PhoneEntry;
The word file by itself indicates an untyped file:
var DataFile: file;
For more information, see Untyped files.
Files are not allowed in arrays or records.
86
|