Name
TextFile Type
Syntax
type TextFile;
Description
The TextFile
type represents a text file. A text
file is different from a binary file in that a text file contains
lines of text, where the size of each line can vary. Unlike standard
Pascal, the TextFile
type is unrelated to
File
of
Char
.
The actual encoding of a line ending is not relevant in a Delphi
program. The ReadLn
and WriteLn
procedures and the Eoln
and
SeekEoln
functions automatically handle line
endings. A text file ends at the end of the file or at the first
occurrence of the #26
character (Ctrl-Z).
Tips and Tricks
By default, text files are buffered with a 128-byte buffer. You can choose a different size buffer by calling
SetTextBuf
.The
TextFile
type is equivalent to the following record. TheSysUtils
unit has a declaration of this type, or you can copy the declaration to your own unit.
type PTextBuf = ^TTextBuf; TTextBuf = array[0..127] of Char; TTextRec = packed record Handle: Integer; Mode: Integer; // fmInput or fmOutput BufSize: Cardinal; // Size of Buffer. BufPos: Cardinal; // Current position in Buffer. BufEnd: Cardinal; // Last position of data in Buffer. BufPtr: PChar; // Pointer to the start of the data in Buffer. OpenFunc: Pointer; // Pointers to functions that take a InOutFunc: Pointer; // var TextFile argument and return an FlushFunc: Pointer; // integer result: zero for success and an CloseFunc: Pointer; // error code for an error. UserData: array[1..32] of Byte; // For your use. Name: array[0..259] of Char; ...
Get Delphi in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.