Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't calculate progress, progress bar inaccurate.

Status
Not open for further replies.

countdrak

Programmer
Jun 20, 2003
358
US
Hi,
I have written an application in delphi that prases a text file and populates a database.

I want my users to see the progress in a progress bar. But my problem is i can't determine the step, because the number of lines in the file keeps chaging everytime a new file is run.

I can get the total number of lines in the file but I couldn't think of a way to determine how many lines have been read already at any given time.

Can someone please help me with some sort of logic on how i can implemnt the progress bar.

Thanks a Lot,
Appreciate it.
 
If Clive's link does not meet your requirements, can you show us the code that reads the text file and determines the number of lines in the file?

It should be fairly simple to add in code to move the progress bar along.

At its simplest your code could look something like:-
Code:
var
  text: TStringList;
  rec: integer;
begin
  text := TStringList.Create;
  try
    text.LoadFromFile ( YourTextFileName );
    ProgressBar.Max := text.count;
    ProgressBar.Min := 0;
    ProgressBar.Position := 0;
    for rec := 0 to text.count - 1 do begin
      YourParseRecordCode ( text[rec] );
      ProgressBar.Position := rec + 1;
      Application.ProcessMessages;
    end;
  finally
    text.free;
  end;
end;

Note that the use of a Progress Bar in this fashion is fairly inefficient. This may or may not matter to you but you could time how long it takes with and without the progress bar to parse a file.

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top