Description |
The FilePos function returns the current position in an open file. The returned value is the Record position, starting at 0 for the file beginning.
The file may be an Untyped, Typed or Text file.
The record length is as follows:
Untyped files | : As set in Reset or ReWrite |
Typed files | : SizeOf the file type |
Text files | : Variable - defined by line ends |
|
|
Notes |
Seek to the given record position only works for binary files.
|
|
Related commands |
Eoln |
|
Returns true if the current text file is pointing at a line end |
File |
|
Defines a typed or untyped file |
Seek |
|
Move the pointer in a binary file to a new record position |
SeekEoln |
|
Skip to the end of the current line or file |
TextFile |
|
Declares a file type for storing lines of text |
|
|
|
Example code : Show the file position in a binary file |
var
myWord, myWord1, myWord2, myWord3 : Word;
myFile : File of Word;
begin // Try to open the Test.cus binary file in write only mode
AssignFile(myFile, 'Test.cus');
ReWrite(myFile);
// Write a few lines of Word data to the file
myWord1 := 123;
myWord2 := 456;
myWord3 := 789;
Write(myFile, myWord1, myWord2, myWord3);
// Close the file
CloseFile(myFile);
// Reopen the file in read only mode
FileMode := fmOpenRead;
Reset(myFile);
// Display the file contents
while not Eof(myFile) do
begin
Read(myFile, myWord); // Note - FilePos shows the after read position
WriteLn('Record '+
IntToStr(FilePos(myFile))+' = '+
IntToStr(myWord));
end;
// Close the file for the last time
CloseFile(myFile);
end;
|
Show full unit code |
Record 1 = 123
Record 2 = 456
Record 3 = 789
|
|