The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



CountLinesInTextFile


Unit:SDL_filesys
Class: none
Declaration: [1] function CountLinesInTextFile (const FVar: TextFile; FeedBack: TFeedbackProc): integer;
[2] function CountLinesInTextFile (const FName: string; FeedBack: TFeedbackProc): integer;

The function CountLinesInTextFile counts the number of lines in the text file specified by FVar or FName. Version [1] requires an open text file, the file pointer is reset by the function. In the case of version [2] the file is opened (and closed) using the filename FName. In order to provide feedback when reading large files a callback routine can be assigned to the parameter FeedBack. The callback routine is called after every 1000 lines and returns the number of currently read lines in the StateCnt parameter of the feedback routine (the PercentDone parameter is always zero).

Example: The following code snippet shows how to create a feedback. Please note the far declaration of the feedback procedure:
uses
  SDL_filesys;


(******************************************************************************)
procedure DoFeedback (Sender: TObject; StateCnt: double; PercentDone: double); far;
(******************************************************************************)

begin
FrmMain.ProgBar1.Value := (round(StateCnt/100000) mod 100);
Application.ProcessMessages;
end;



(******************************************************************************)
procedure TFrmMain.Button1Click(Sender: TObject);
(******************************************************************************)

var
  IFile : TextFile;
  nlin  : integer;

begin
if ODiag.Execute then
  begin
  AssignFile (IFile, ODiag.FileName);
  reset (IFile);
  nlin := CountLinesInTextFile (IFile, DoFeedback);
  closefile (IFile);
  end;
end;



Last Update: 2023-Feb-06