SmartPascal
SeekEof
Function
Skip to the end of the current line or file System unit
 function SeekEof ( {var FileHandle : File} ) : Boolean;
Description
The SeekEof procedure skips past white space characters in the current record in an open text file given by FileHandle.
 
The file must have been assigned with AssignFile and opened with Reset.
 
If the end of file (Eof) is thereby reached, the return value is True.
 
This function is normally used when reading unknown numbers of records in a file.
Notes
SeekEof is very similar to SeekEoln - the only difference is that SeekEof only returns true when Eof is reached; SeekEoln also returns true when the line end is reached after skipping the white spaces.
Related commands
Eof Returns true if a file opened with Reset is at the end
Eoln Returns true if the current text file is pointing at a line end
File Defines a typed or untyped file
FilePos Gives the file position in a binary or text file
Seek Move the pointer in a binary file to a new record position
SeekEoln Skip to the end of the current line or file
 
Example code : Reading all records in 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
  SysUtils,
  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;
  number : Integer;

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

  // Write numbers in a string
  WriteLn(myFile, '1 2 3 4   ');   // White space at the end

  // Write numbers as separate parameters
  WriteLn(myFile, 5, ' ', 6, ' ', 7, ' ');  // Results in '5 6 7 ' text

  // Close the file
  CloseFile(myFile);

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

  // Display the file contents
  while not SeekEof(myFile) do
  begin
    // Read numbers one at a time
    ShowMessage('Start of a new line');
    while not SeekEoln(myFile) do
    begin
      Read(myFile, number);
      ShowMessage(IntToStr(number));
    end;

    // Now move to the next line
    ReadLn(myFile);
  end;

  // Close the file for the last time
  CloseFile(myFile);
end;
 
end.
Hide full unit code
   Start of a new line
   1
   2
   3
   4
   Start of a new line
   5
   6
   7