Node:AnyFile, Next:Append, Previous:AnsiChar, Up:Reference
type AnyFile { built-in type }
AnyFile
is a built-in type that can only be used for
parameters and pointer targets. Any kind of file variable
(Text
, untyped and typed file
) can be passed to such a
parameter and their address assigned to such a pointer. On the other
side, only generic file operations are possible with AnyFile
parameters/pointer targets.
This type is useful for implementing generic file handling routines.
Also some built-in file routines use this type for their parameters,
e.g. IOSelectRead
(see Run Time System).
BlockRead
(see BlockRead) and BlockWrite
(see BlockWrite) treat AnyFile
specially, in that they
accept all AnyFile
s as arguments (even if the actual file is
a typed or Text
file) and always use a block size of 1 (even
if the actual file is an untyped file with different block size or a
typed file of a type with size not equal to one). This is the only
way to reliably read/write a certain amount of data from/to an
AnyFile
.
AnyFile
pointers cannot be allocated with New
(because
it would be unspecified which kind of file to create).
AnyFile
is a GNU Pascal extension.
program AnyFileDemo; procedure Test (var f: AnyFile); var v: ^AnyFile; begin { Generic file operations are allowed for `AnyFile' } Rewrite (f); { `AnyFile' can also be accessed via pointers } v := @f; Close (v^) end; var t: Text; f: file; g: file of Integer; begin { Any kind of file variable can be passed as `AnyFile' } Test (t); Test (f); Test (g) end.