Gives the file position in a binary or text file System unit
1  function FilePos ( var FileHandle : File; ) : LongInt;
2  function FilePos ( var FileHandle : TextFile; ) ;
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
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
 Author links

 Buy Website Traffic at

 Buy Proxies at
 Download this web site as a Windows program.

Example code : Show the file position in a binary file
  myWord, myWord1, myWord2, myWord3 : Word;
  myFile : File of Word;

  // Try to open the Test.cus binary file in write only mode
  AssignFile(myFile, 'Test.cus');

  // Write a few lines of Word data to the file
  myWord1 := 123;
  myWord2 := 456;
  myWord3 := 789;
  Write(myFile, myWord1, myWord2, myWord3);

  // Close the file

  // Reopen the file in read only mode
  FileMode := fmOpenRead;

  // Display the file contents
  while not Eof(myFile) do
    Read(myFile, myWord);
    // Note - FilePos shows the after read position
    ShowMessage('Record '+
                IntToStr(FilePos(myFile))+' = '+

  // Close the file for the last time
Show full unit code
   Record 1 = 123
   Record 2 = 456
   Record 3 = 789
Delphi Programming Neil Moffatt 2002 - 2016. All rights reserved.  |  Home Page