ObjectPascal
Eof
Function
Returns true if a file opened with Reset is at the end System unit
 function Eof ( var FileHandle : TextFile ) ;
Description
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.
Notes
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
BlockRead Reads a block of data records from an untyped binary file
Eoln Returns true if the current text file is pointing at a line end
Read Read data from a binary or text file
ReadLn Read a complete line of data from a text file
SeekEof Skip to the end of the current line or file
SeekEoln Skip to the end of the current line or file
 
Example code : Reading to the end of a text file
var
  myFile : TextFile;
  text   : string;

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

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

  // Close the file
  CloseFile(myFile);

  // Reopen the file in read only mode
  Reset(myFile);

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

  // Close the file for the last time
  CloseFile(myFile);
end;
Show full unit code
   Hello
   World