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 |
// Full Unit code. // ----------------------------------------------------------- // You must store this code in a unit called Unit1 with a form // called Form1 that has an OnCreate event called FormCreate. unit Unit1; interface uses // The System unit does not need to be defined Forms, Dialogs; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} // Include form definitions procedure TForm1.FormCreate(Sender: TObject); 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; end.
|
Hide full unit code |
Hello
World
|
|