DelphiBasics
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
EofReturns true if a file opened with Reset is at the end
EolnReturns true if the current text file is pointing at a line end
FileDefines a typed or untyped file
FilePosGives the file position in a binary or text file
SeekMove the pointer in a binary file to a new record position
SeekEolnSkip to the end of the current line or file
 Download this web site as a Windows program.




 
Example code : Reading all records in a text file
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;
Show full unit code
  Start of a new line
  1
  2
  3
  4
  Start of a new line
  5
  6
  7
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page