Quick start manual

8-4
Delphi Language Guide
Text file device drivers
Some of the standard I/O routines that work on text files don’t need to have a file
variable explicitly given as a parameter. If the file parameter is omitted, Input or
Output is assumed by default, depending on whether the procedure or function is
input- or output-oriented. For example, Read(X) corresponds to Read(Input, X) and
Write(X) corresponds to Write(Output, X).
If you do specify a file when calling one of the input or output routines that work on
text files, the file must be associated with an external file using AssignFile, and
opened using Reset, Rewrite, or Append. An error occurs if you pass a file that was
opened with Reset to an output-oriented procedure or function. An error also occurs
if you pass a file that was opened with Rewrite or Append to an input-oriented
procedure or function.
Untyped files
Untyped files are low-level I/O channels used primarily for direct access to disk files
regardless of type and structuring. An untyped file is declared with the word file
and nothing more. For example,
var DataFile: file;
For untyped files, the Reset and Rewrite procedures allow an extra parameter to
specify the record size used in data transfers. For historical reasons, the default
record size is 128 bytes. A record size of 1 is the only value that correctly reflects the
exact size of any file. (No partial records are possible when the record size is 1.)
Except for Read and Write, all typed-file standard procedures and functions are also
allowed on untyped files. Instead of Read and Write, two procedures called BlockRead
and BlockWrite are used for high-speed data transfers.
Text file device drivers
You can define your own text file device drivers for your programs. A text file device
driver is a set of four functions that completely implement an interface between
Delphi’s file system and some device.
The four functions that define each device driver are Open, InOut, Flush, and Close.
The function header of each function is
function DeviceFunc(var F: TTextRec): Integer;
where DeviceFunc is the name of the function (that is, Open, InOut, Flush, or Close). For
information about the TTextRec type, see the online Help. The return value of a
device-interface function becomes the value returned by IOResult. If the return value
is zero, the operation was successful.