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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can this code be improved?

Status
Not open for further replies.

topcat01

Programmer
Jul 10, 2003
83
GB
I have the following code for displaying a progress bar whilst progressing through a file, this has served its purpose for some time now but wondered if there is a more efficient way to code this?

Code:
repeat
  ProgressBar1.Position := Round((Sourcefile.Position/Sourcefile.Size) * 100);
  Application.ProcessMessages;

  ...some code other here

until Sourcefile.Position >= Sourcefile.Size;

Thanks
 
this has served its purpose for some time now but wondered if there is a more efficient way to code this?

Yes, you can change the minimums and maximums in the control and let the control do the job you are doing in your ProgressBar1.Position line.

Untested, but the general idea is there:
Code:
ProgressBar1.Min := 0;
ProgressBar1.Max := Sourcefile.size);
repeat
  ProgressBar1.Position := Sourcefile.Position;
  Application.ProcessMessages;
  ...some code other here
until Sourcefile.Position >= Sourcefile.Size;
 
Glen9999's code is a good approach, you just need to be aware that if your Sourcefile.Size > 2GB, then this approach won't work, as TProgressBar.Position is of type Integer, at least it is in Delphi 6.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top