Mega Code Archive

 
Categories / Delphi / Functions
 

Seekeof - 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 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