Name
FilePos Function
Syntax
function FilePos(var F: File): LongInt; function FilePos(var F: TextFile): LongInt;
Description
FilePos returns the
current position (as a record number) in the file
F. The beginning of the file is position zero. If
F is a TextFile, the record
size is arbitrarily chosen as the buffer size, which defaults to 128.
When Eof(F) is True, FilePos
returns the number of records in the file. FilePos
is not a real function.
Errors
If the file
Fis not open,FilePosreports I/O error 103.Although you can get the file position in a text file, you cannot use it to seek to that position. The
Seekprocedure works only with binary files. To get a file position of a text file, use the Windows API:
// Return a byte position in a text file if its buffer is empty. function TextFilePos(var F: TextFile): LongInt; begin Result := SetFilePointer(TTextRec(F).Handle, 0, nil, File_Current); end;
FilePosdoes not support files larger than 2 GB. See theFileSeekfunction in theSysUtilsunit, or call the Windows API for large files.
See Also
| Eof Function, File Keyword, FileSize Function, IOResult Function, Seek Procedure, TextFile Type, Truncate Procedure |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access