Returns true if a file opened with Reset is at the end System unit
 function Eof(var FileHandle TextFile);
The Eof function returns true if the file given by FileHandle is at the end.
The file must have been assigned, and opened with Reset.
Warning after reading the last line of a file, Eof will be true, even though data has been read successfully.

So use Eof before reading, to see if reading is required.
Related commands
BlockReadReads a block of data records from an untyped binary file
EolnReturns true if the current text file is pointing at a line end
ReadRead data from a binary or text file
ReadLnRead a complete line of data from a text file
SeekEofSkip to the end of the current line or file
SeekEolnSkip to the end of the current line or file
 Download this web site as a Windows program.

Example code : Reading to the end of a text file
  myFile : TextFile;
  text   : string;

  // Try to open the Test.txt file for writing to
  AssignFile(myFile, 'Test.txt');

  // Write a couple of well known words to this file
  WriteLn(myFile, 'Hello');
  WriteLn(myFile, 'World');

  // Close the file

  // Reopen the file in read only mode

  // Display the file contents
  while not Eof(myFile) do
    ReadLn(myFile, text);

  // Close the file for the last time
Show full unit code
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page