RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
System.Eof Function

Tests whether the file position is at the end of a file.

Pascal
function Eof: Boolean; overload;
function Eof(var F): Boolean; overload;
function Eof(var F: Text): Boolean; overload;
C++
Boolean Eof();
Boolean Eof( F);
Boolean Eof(Text F);

In Delphi code, Eof tests whether the current file position is the end-of-file. F is a file variable that has been opened for reading. If F is omitted, the standard file variable Input is assumed.  

Eof(F) returns true if the current file position is beyond the last character of the file or if the file is empty; otherwise, Eof(F) returns false.

Note: Eof fails if the file F has been opened in write-only mode. For example, you can't use Eof with files opened using the Append or Rewrite, which open a file in write-only mode.
 

Delphi Examples: 

 

{
This example reads a file one character at a time and writes
it into a file of your chosing.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  F1, F2: TextFile;
  Ch: AnsiChar;
begin
  if OpenDialog1.Execute then begin
    AssignFile(F1, OpenDialog1.Filename);
    Reset(F1);
    if SaveDialog1.Execute then begin
      AssignFile(F2, SaveDialog1.Filename);
      Rewrite(F2);
      while not Eof(F1) do
      begin
        Read(F1, Ch);
        Write(F2, Ch);
      end;
      CloseFile(F2);
    end;
    CloseFile(F1);
  end;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!