TProgressBar buggy? lazarus / 31-LCL ---------------------------------------------------------------------- kupferstecher · 2018-05-20 18:09 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   Progressbar1.Visible:= true;   Progressbar1.Position:= 3; Progressbar1.Refresh; sleep(10);  Progressbar1.Position:= 13; Progressbar1.Refresh;  Progressbar1.Position:= 20; Progressbar1.Refresh;  Progressbar1.Position:= 25; Progressbar1.Refresh; sleep(200);  Progressbar1.Position:= 30; Progressbar1.Refresh;  Progressbar1.Position:= 40; Progressbar1.Refresh;  Progressbar1.Position:= 45; Progressbar1.Refresh; sleep(400);  Progressbar1.Position:= 53; Progressbar1.Refresh;  Progressbar1.Position:= 60; Progressbar1.Refresh;  Progressbar1.Position:= 70; Progressbar1.Refresh; sleep(200);  Progressbar1.Position:= 80; Progressbar1.Refresh;  Progressbar1.Position:= 92; Progressbar1.Refresh;  Progressbar1.Position:= 100; Progressbar1.Refresh;  //Application.ProcessMessages; // <- doesnt help either  sleep(2000);  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 ---------------------------------------------------------------------- Blaazen · 2018-05-20 18:22 Demo works as expected on Linux+Qt. EDIT: Under Wine works too. ---------------------------------------------------------------------- balazsszekely · 2018-05-20 18:42 @kupferstecher Quotein 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure StepIt(const APB: TProgressBar; const APos: Integer);begin  APB.Position := APos; //workaround for progressbar animation bug(vista+)   if APos < APB.Max  then  begin    APB.Position := APos + 1;    APB.Position := APB.Position - 1;  end  else  begin    APB.Max := APB.Max + 1;    APB.Position := APB.Max;    APB.Position := APB.Position - 1;    APB.Max := APB.Max - 1;  end;  //end workaround  Sleep(200);end;  procedure TForm1.ButtonStartClick(Sender: TObject);begin  Progressbar1.Visible := True;  StepIt(ProgressBar1, 3);  StepIt(ProgressBar1, 13);  StepIt(ProgressBar1, 20);  StepIt(ProgressBar1, 25);  StepIt(ProgressBar1, 30);  StepIt(ProgressBar1, 40);  StepIt(ProgressBar1, 45);  StepIt(ProgressBar1, 53);  StepIt(ProgressBar1, 60);  StepIt(ProgressBar1, 70);  StepIt(ProgressBar1, 80);  StepIt(ProgressBar1, 92);  StepIt(ProgressBar1, 100);  Progressbar1.Visible := False;end; PS: You can ifdef the workaround code if you target multiple platforms. ---------------------------------------------------------------------- Blaazen · 2018-05-20 18:51 It seems that Windows are worse and worse with every new version. ---------------------------------------------------------------------- Zoran · 2018-05-20 18:53 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. ---------------------------------------------------------------------- balazsszekely · 2018-05-20 18:54 @Blaazen QuoteIt seems that Windows are worse and worse with every new version. I think win98 was the crappiest "surpassed" only by win95. ---------------------------------------------------------------------- Zoran · 2018-05-20 19:02 Quote from: GetMem on May 20, 2018, 08:54:30 pm@Blaazen QuoteIt seems that Windows are worse and worse with every new version. I think win98 was the crappiest "surpassed" only by win95. Actually, both were the best OS-s for personal PC's at their time. ---------------------------------------------------------------------- balazsszekely · 2018-05-20 19:11 QuoteActually, 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 · 2018-05-20 19:25 Thanks for the replys and tests! Quote from: GetMem on May 20, 2018, 08:42:11 pmFrom 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 · 2018-05-20 19:44 Quote from: Blaazen on May 20, 2018, 08:51:59 pmIt seems that Windows are worse and worse with every new version. I have a tablet with W10... It's a s***** ---------------------------------------------------------------------- kupferstecher · 2018-05-20 20:59 Well, didn't they say it'll be the last Windows? So there's hope~ ---------------------------------------------------------------------- JD · 2018-05-20 22:46 Quote from: GAN on May 20, 2018, 09:44:09 pmQuote from: Blaazen on May 20, 2018, 08:51:59 pmIt 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! ---------------------------------------------------------------------- jamie · 2018-05-20 23:03 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 · 2018-05-21 08:11 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?