* * *

Author Topic: TProgressBar buggy?  (Read 1161 times)

kupferstecher

  • Full Member
  • ***
  • Posts: 218
TProgressBar buggy?
« on: May 20, 2018, 08:09:22 pm »
Hello,

in my project I want to use a TProgressBar, but it doesn't show the correct positions. I'm not sure if I'm doing it wrong. Attached a minimum project. When I push the start button, the progress bar should go from 0 to full scale in a few steps, but it stops on the half way as shown in the attached screenshot. The code for running the progress bar is as follows:

Code: Pascal  [Select]
  1.   Progressbar1.Visible:= true;
  2.  
  3.   Progressbar1.Position:= 3; Progressbar1.Refresh; sleep(10);
  4.   Progressbar1.Position:= 13; Progressbar1.Refresh;
  5.   Progressbar1.Position:= 20; Progressbar1.Refresh;
  6.   Progressbar1.Position:= 25; Progressbar1.Refresh; sleep(200);
  7.   Progressbar1.Position:= 30; Progressbar1.Refresh;
  8.   Progressbar1.Position:= 40; Progressbar1.Refresh;
  9.   Progressbar1.Position:= 45; Progressbar1.Refresh; sleep(400);
  10.   Progressbar1.Position:= 53; Progressbar1.Refresh;
  11.   Progressbar1.Position:= 60; Progressbar1.Refresh;
  12.   Progressbar1.Position:= 70; Progressbar1.Refresh; sleep(200);
  13.   Progressbar1.Position:= 80; Progressbar1.Refresh;
  14.   Progressbar1.Position:= 92; Progressbar1.Refresh;
  15.   Progressbar1.Position:= 100; Progressbar1.Refresh;
  16.   //Application.ProcessMessages; // <- doesnt help either
  17.   sleep(2000);
  18.   Progressbar1.Visible:= false;

The two seconds before the progress bar is hidden, the progress bar should be on position 100% (in my understanding), but it isn't.

Do I miss something or is this a bug?

Thanks!


My setup:
Win7, 64bit
Lazarus 1.8.0
FPC 3.0.4
Target: Win32
« Last Edit: May 20, 2018, 08:12:23 pm by kupferstecher »

Blaazen

  • Hero Member
  • *****
  • Posts: 2640
  • POKE 54296,15
    • Eye-Candy Controls
Re: TProgressBar buggy?
« Reply #1 on: May 20, 2018, 08:22:10 pm »
Demo works as expected on Linux+Qt.

EDIT: Under Wine works too.
« Last Edit: May 20, 2018, 08:26:08 pm by Blaazen »
Lazarus 2.1.0 r59317M FPC 3.3.1 r39660 x86_64-linux-qt Chakra, Qt 4.8.7/5.11.1, Plasma 5.13.5
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.14

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

GetMem

  • Hero Member
  • *****
  • Posts: 3195
Re: TProgressBar buggy?
« Reply #2 on: May 20, 2018, 08:42:11 pm »
@kupferstecher
Quote
in my project I want to use a TProgressBar, but it doesn't show the correct positions. I'm not sure if I'm doing it wrong. Attached a minimum project. When I push the start button, the progress bar should go from 0 to full scale in a few steps, but it stops on the half way as shown in the attached screenshot. The code for running the progress bar is as follows:

The bug has nothing to do with TProgressBar and you did not do anything wrong. From vista+ windows animates the progressbar, this cause the lag. Here is a workaround:
Code: Pascal  [Select]
  1. procedure StepIt(const APB: TProgressBar; const APos: Integer);
  2. begin
  3.   APB.Position := APos;
  4.  //workaround for progressbar animation bug(vista+)
  5.   if APos < APB.Max  then
  6.   begin
  7.     APB.Position := APos + 1;
  8.     APB.Position := APB.Position - 1;
  9.   end
  10.   else
  11.   begin
  12.     APB.Max := APB.Max + 1;
  13.     APB.Position := APB.Max;
  14.     APB.Position := APB.Position - 1;
  15.     APB.Max := APB.Max - 1;
  16.   end;
  17.   //end workaround
  18.   Sleep(200);
  19. end;
  20.  
  21.  
  22. procedure TForm1.ButtonStartClick(Sender: TObject);
  23. begin
  24.   Progressbar1.Visible := True;
  25.   StepIt(ProgressBar1, 3);
  26.   StepIt(ProgressBar1, 13);
  27.   StepIt(ProgressBar1, 20);
  28.   StepIt(ProgressBar1, 25);
  29.   StepIt(ProgressBar1, 30);
  30.   StepIt(ProgressBar1, 40);
  31.   StepIt(ProgressBar1, 45);
  32.   StepIt(ProgressBar1, 53);
  33.   StepIt(ProgressBar1, 60);
  34.   StepIt(ProgressBar1, 70);
  35.   StepIt(ProgressBar1, 80);
  36.   StepIt(ProgressBar1, 92);
  37.   StepIt(ProgressBar1, 100);
  38.   Progressbar1.Visible := False;
  39. end;

PS: You can ifdef the workaround code if you target multiple platforms.

Blaazen

  • Hero Member
  • *****
  • Posts: 2640
  • POKE 54296,15
    • Eye-Candy Controls
Re: TProgressBar buggy?
« Reply #3 on: May 20, 2018, 08:51:59 pm »
It seems that Windows are worse and worse with every new version.
Lazarus 2.1.0 r59317M FPC 3.3.1 r39660 x86_64-linux-qt Chakra, Qt 4.8.7/5.11.1, Plasma 5.13.5
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.14

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Zoran

  • Hero Member
  • *****
  • Posts: 1253
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: TProgressBar buggy?
« Reply #4 on: May 20, 2018, 08:53:57 pm »
Testing your application under Linux Mint 1.8 Mate, Lazarus 1.8.4, FPC 3.0.4:

With Gtk2:
No progress is shown. Absolutely nothing.
Only when Application.ProcessMessages is added after each step, the progress is shown correctly. So, ProgressBar1.Refresh does nothing.

With Qt, however, it works correctly.
Further, when removing all Refresh calls, it also works!

Clearly, Qt and Gtk2 behave differently. Should be reported on bugtracker.

GetMem

  • Hero Member
  • *****
  • Posts: 3195
Re: TProgressBar buggy?
« Reply #5 on: May 20, 2018, 08:54:30 pm »
@Blaazen
Quote
It seems that Windows are worse and worse with every new version.
:D I think win98 was the crappiest "surpassed" only by win95.
« Last Edit: May 20, 2018, 08:57:11 pm by GetMem »

Zoran

  • Hero Member
  • *****
  • Posts: 1253
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: TProgressBar buggy?
« Reply #6 on: May 20, 2018, 09:02:49 pm »
@Blaazen
Quote
It seems that Windows are worse and worse with every new version.
:D I think win98 was the crappiest "surpassed" only by win95.

Actually, both were the best OS-s for personal PC's at their time.

GetMem

  • Hero Member
  • *****
  • Posts: 3195
Re: TProgressBar buggy?
« Reply #7 on: May 20, 2018, 09:11:04 pm »
Quote
Actually, both were the best OS-s for personal PC's at their time.
I did some programming on win98 with Delphi3-5/Visual studio 6. I remember I had to restart windows countless time because of the internal access violations. XP was a breath of fresh air and a life saver.

kupferstecher

  • Full Member
  • ***
  • Posts: 218
Re: TProgressBar buggy?
« Reply #8 on: May 20, 2018, 09:25:34 pm »
Thanks for the replys and tests!

From vista+ windows animates the progressbar, this cause the lag.
I just tested and removed the "Progressbar1.Visible:= false;". Then it works (at least it gets to 100%). Seems the application needs idle time to do the animation. So my mistake (I know :) was to use the main thread for the actual work.

Your workaround works fine! But it still is quite a hack, I consider making an own progress bar based on a stretched image, instead.

GAN

  • Full Member
  • ***
  • Posts: 190
Re: TProgressBar buggy?
« Reply #9 on: May 20, 2018, 09:44:09 pm »
It seems that Windows are worse and worse with every new version.

I have a tablet with W10... It's a s*****
Lazarus 1.6 FPC 3.0.0 Linux Mint Mate 17.2 x86_64 GTK-2
Zeos 7.1.3 - Sqlite 3.8.2

Foro Lazarus en español http://forum.lazarus.freepascal.org/index.php/board,73.0.html

kupferstecher

  • Full Member
  • ***
  • Posts: 218
Re: TProgressBar buggy?
« Reply #10 on: May 20, 2018, 10:59:04 pm »
Well, didn't they say it'll be the last Windows? So there's hope~

JD

  • Hero Member
  • *****
  • Posts: 1728
Re: TProgressBar buggy?
« Reply #11 on: May 21, 2018, 12:46:20 am »
It seems that Windows are worse and worse with every new version.

I have a tablet with W10... It's a s*****

Agreed. I would never buy a tablet with Windows 10. I've tested them and they can't seem to decide if they are computers or tablets. They are schizophrenic!  :D
Windows (10, 7) - Lazarus 1.8/FPC 3.0.4, NewPascal, Delphi
Linux Mint Cinnamon  - Lazarus 1.8/FPC 3.0.4, NewPascal

Indy 10.6 series; mORMot; Zeos 7.2.1; SQLite, Firebird, PostgreSQL & MariaDB; VirtualTreeView 5.5.3 R1

jamie

  • Hero Member
  • *****
  • Posts: 837
Re: TProgressBar buggy?
« Reply #12 on: May 21, 2018, 01:03:10 am »
Like most native controls in windows, it works via messages..

The Refresh does nothing but request the control to update via the message system...

you need to ether allow the message system to cycle through or call the Application.Processmessages between..

doing the REPAINT may or may not work directly..

kupferstecher

  • Full Member
  • ***
  • Posts: 218
Re: TProgressBar buggy?
« Reply #13 on: May 21, 2018, 10:11:27 am »
The Application.Processmessages doesn't work, at least if its not done always. It seems the animation is calculated/rendered within the application thread. I didn't expect that.

Does that mean that api calls and the OS-code lying behind are always (or normally) done in the application thread itself and not in a OS-thread?

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus