ProgresBar - display message after the bar reaches 100%

-1

I am playing around with progress bars ... trying to display a message when the progress bar reaches the end of the line (100%) ( I used the Raize Status bar and TMS AdvProgressBar) For Raize, this code sample seem to work :

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  rzprogressstatus1.Percent := rzprogressstatus1.Percent +1;
  if rzprogressstatus1.Percent = 100 then begin
    showmessage('Yo');
    application.Terminate;
  end;
end;

However,for AdvProgressBar it does not because it keeps firing messages constantly when position reaches 100.That makes me worry if Raize is maybe in trouble.

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  AdvProgressBar1.Position := AdvProgressBar1.Position +1;
  if AdvProgressBar1.Position = 100 then begin
    showmessage('Yo');
    application.Terminate;
  end;
end;

edit : debugger shows :

First chance exception at $00649D6C. Exception class $C0000005 with message 'access violation at 0x00649d6c: read of address 0x00000048'. Process Project1.exe (2928) and stops on the following code :

procedure TTimer.SetEnabled(Value: Boolean);
begin
  if Value <> FEnabled then begin
    FEnabled := Value;
    UpdateTimer;
  end;
end;

Like I said,I would like to display a message when the bar reaches the end and then terminate the application. What am I missing here ? Is there a better way to do it ?

delphi
delphi-xe4
tms
asked on Stack Overflow Oct 6, 2013 by user763539 • edited Oct 7, 2013 by Johan

1 Answer

2

If you need to use a timer and you do something time consuming (showing a dialog is time consuming) you should always turn the timer off at the start of the timer event and turn it on again at the end (if neccessary)

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := False;
  AdvProgressBar1.Position := AdvProgressBar1.Position +1;
  if AdvProgressBar1.Position = 100 then begin
    showmessage('Yo');
    application.Terminate;
  end;
  Timer1.Enabled := True;
end;
answered on Stack Overflow Oct 7, 2013 by fuchs777

User contributions licensed under CC BY-SA 3.0