DelphiBasics
Eoln
Function
Returns true if the current text file is pointing at a line end System unit
 function Eoln ( var FileHandle : TextFile ) : Boolean;
Description
The Eoln function returns true if the current file given by FileHandle is positioned at the end of the current line.
 
The file must have been assigned using AssignFile, and opened with Reset.
 
The Eoln function is used with the Read procedure to know when the end of the current line has been reached.
 
More specifically, it is only needed when reading character data - reading numeric data treats the end of line as white space, and skips past it when looking for the next number.
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
Eof Returns true if a file opened with Reset is at the 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
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

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


 
Example code : Reading one character at a time from a text file line
var
  myFile : TextFile;
  letter : char;
  text   : string;

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

  // Write lines of text to the file
  WriteLn(myFile, 'Hello');
  WriteLn(myFile, 'To you');

  // Close the file
  CloseFile(myFile);

  // Reopen the file for reading
  Reset(myFile);

  // Display the file contents
  while not Eof(myFile) do
  begin
    // Proces one line at a time
    ShowMessage('Start of a new line :');
    while not Eoln(myFile) do
    begin
      Read(myFile, letter);   // Read and display one letter at a time
      ShowMessage(letter);
    end;
    ReadLn(myFile, text);
  end;

  // Close the file for the last time
  CloseFile(myFile);
end;
Show full unit code
   Start of a new line :
   H
   e
   l
   l
   o
   Start of a new line :
   T
   o
  
   y
   o
   u
 
Delphi Programming Neil Moffatt 2002 - 2016. All rights reserved.  |  Home Page