Recent

Author Topic: TProgressBar issue. Bar does not update and...  (Read 1731 times)

Yukiko

  • Jr. Member
  • **
  • Posts: 55
TProgressBar issue. Bar does not update and...
« on: October 21, 2018, 08:06:12 am »
You all have been so helpful in the past. Hopefully you can help me solve my current issue.

I created a Form that is supposed to report on the file copy progress for 59 files. On that form I placed a TProgress component. I set the .Min to 0, the .Max to 59, and the .Step to 1. When the file copy function starts it .Shows the form and I get 1 bar on the TProgressBar that is larger than 1/59th of the progress bar's area and in a few seconds Windows reports that the program is not responding. The progress bar does not update further at this point. However the main program is still copying the files and eventually the progress bar suddenly fills all of the way when all of the files are copied. I am not sure if I am doing something wrong or if there is a problem with the TProgressBar component. After each CopyFile() call I update the .Position on the TProgressBar by 1 but something is happening that prevents the bar from updating during the file copy process. I searched the forums for ProgressBar problems but did not get any hits that address my issue. The version of Lazarus I am using is 1.8.0 on a Windows 10 machine. Below is a snippet of what I am doing. Right ow it is a bunch of repeating lines of code. I will optimize it later once I get this working.

Code: Pascal  [Select][+][-]
  1. CopyFile(UODirName + '/artLegacyMUL.uop', POLDirName + '/' + UoDataFileRoot.Text + '/artLegacyMUL.uop');
  2. FileCopyProgBar.Position:=FileCopyProgBar.Position + 1;
  3. CopyFile(UODirName + '/art.mul', POLDirName + '/' + UoDataFileRoot.Text + '/art.mul');
  4. FileCopyProgBar.Position:=FileCopyProgBar.Position + 1;
  5.  

eric

  • Sr. Member
  • ****
  • Posts: 267
Re: TProgressBar issue. Bar does not update and...
« Reply #1 on: October 21, 2018, 08:15:54 am »
Add:
Code: [Select]
Application.ProcessMessages;at the end of each iteration of the loop.

Yukiko

  • Jr. Member
  • **
  • Posts: 55
Re: TProgressBar issue. Bar does not update and...
« Reply #2 on: October 21, 2018, 08:28:03 am »
Thank you.
This tells Windows to process the message that the main program sent to my form. I haven't used "dynamic" objects on a form until now. I naively figured Windows would just handle it automatically. Crazy me.

 

TinyPortal © 2005-2018