File types are represented as
records. Typed files and untyped files occupy 332 bytes, which are laid out as
follows:
type
TFileRec = packed record
Handle: Integer;
Mode: word;
Flags: word;
case Byte of
0: (RecSize: Cardinal);
1: (BufSize: Cardinal;
BufPos:
Cardinal;
BufEnd:
Cardinal;
BufPtr:
PChar;
OpenFunc:
Pointer;
InOutFunc:
Pointer;
FlushFunc:
Pointer;
CloseFunc:
Pointer;
UserData: array[1..32]
of Byte;
Name: array[0..259]
of Char; );
end;
Text files occupy 460 bytes, which
are laid out as follows:
type
TTextBuf = array[0..127] of Char;
TTextRec = packed record
Handle: Integer;
Mode: word;
Flags: word;
BufSize: Cardinal;
BufPos: Cardinal;
BufEnd: Cardinal;
BufPtr: PChar;
OpenFunc: Pointer;
InOutFunc: Pointer;
FlushFunc: Pointer;
CloseFunc: Pointer;
UserData: array[1..32] of Byte;
Name: array[0..259] of Char;
Buffer: TTextBuf;
end;
Handle contains the file’s handle (when the file is open).
The Mode field can assume
one of the values
const
fmClosed = $D7B0;
fmInput = $D7B1;
fmOutput = $D7B2;
fmInOut = $D7B3;
where fmClosed indicates that the
file is closed, fmInput and fmOutput indicate a text file that
has been reset (fmInput) or rewritten (fmOutput), fmInOut
indicates a typed or untyped file that has been reset or rewritten. Any other
value indicates that the file variable is not assigned (and hence not
initialized).
The UserData field is
available for user-written routines to store data in.
Name contains the file name, which is a sequence of characters
terminated by a null character (#0).
For typed files and untyped files,
RecSize contains the record length in bytes, and the Private
field is unused but reserved.
For text files, BufPtr is a
pointer to a buffer of BufSize bytes, BufPos is the index of the
next character in the buffer to read or write, and BufEnd is a count of
valid characters in the buffer. OpenFunc, InOutFunc, FlushFunc,
and CloseFunc are pointers to the I/O routines that control the file;
see Device
functions. Flags determines the line break style as follows:
bit 0 clear LF
line breaks
bit 0 set CRLF
line breaks
All other Flags bits are reserved for future use. See also DefaultTextLineBreakStyle and SetLineBreakStyle.
文件类型表示为记录。类型文件变量和无类型文件变量占用332个字节,它们被如下布局:
type
TFileRec = packed record
Handle: Integer;
Mode: word;
Flags: word;
case Byte of
0: (RecSize: Cardinal);
1: (BufSize: Cardinal;
BufPos:
Cardinal;
BufEnd:
Cardinal;
BufPtr:
PChar;
OpenFunc:
Pointer;
InOutFunc:
Pointer;
FlushFunc:
Pointer;
CloseFunc:
Pointer;
UserData: array[1..32]
of Byte;
Name: array[0..259]
of Char; );
end;
文本文件变量占用460个字节,如下布局:
type
TTextBuf = array[0..127] of Char;
TTextRec = packed record
Handle: Integer;
Mode: word;
Flags: word;
BufSize: Cardinal;
BufPos: Cardinal;
BufEnd: Cardinal;
BufPtr: PChar;
OpenFunc: Pointer;
InOutFunc: Pointer;
FlushFunc: Pointer;
CloseFunc: Pointer;
UserData: array[1..32] of Byte;
Name: array[0..259] of Char;
Buffer: TTextBuf;
end;
Handle包含了文件的句柄(当文件打开时)
Mode字段可以是下列值:
const
fmClosed = $D7B0;
fmInput = $D7B1;
fmOutput = $D7B2;
fmInOut = $D7B3;
这里的fmClosed表示文件是关闭的,fmInput和fmOutput表示文本文件已经被复位(fmInput)或重写(fmOutput),fmInOut表示一个类型文件或无类型文件已经被复位或重写。其他任何值都表示文件变量没有被指定(用标准过程AssignFile)到外部文件(因此是没有被初始化的)。
UserData字段可以用于用户编写的例程在其中存储数据。
Name包含了文件名,它是一个以NULL字符(#0)结尾的字符序列。
对于类型文件和无类型文件,RecSize包含了字段长度(以字节),Private字段未被使用(保留的)。
对于文本文件,BufPtr是一个指针,该指针指向的缓冲区其尺寸为BufSize个字节,BufPos是缓冲区中要读或写的下一个字符的索引,BufEnd表示缓冲区中有效字符的个数。OpenFunc、InOutFunc、FlushFunc和CloseFunc等指针指向控制文件输入输出(I/O)的例程,见设备函数。Flags确定行终止的类型:
状态 类型
bit 0 清除 LF(换行)
bit 0 值为1 CRLF(回车换行)
Flags中其他所有的位都是保留为将来使用。还可以参考DefaultTextLineBreakStyle和SetLineBreakStyle。