Sina
Sina

Reputation: 11

I can't repaint my form in Delphi

I'm creating a Delphi program and i have this code in my program:

begin
  if edit1.Text='salam' then
  begin
    for i := 1 to 10 do
    begin
      progressbar1.Value := progressbar1.Value+1;
      sleep(100);
    end;
  end;
end;

I wanna have the progressbar moving smoothly. But this code isn't like that.
What should i do? I wanna repaint the form after sleep.

Upvotes: 0

Views: 1196

Answers (1)

Cesar
Cesar

Reputation: 498

You should do it like this...

begin
  if edit1.Text='salam' then
  begin
    progressbar1.Step:=1;
    for i := 1 to 10 do
    begin
      progressbar1.StepIt;
      Application.ProcessMessages;
      Sleep(100);
    end
  end;
end;

Windows needs to process the messages to repaint and to know your app isn't frezzed, Application.ProcessMessages does that magic.

Upvotes: 1

Related Questions