How to wait for TTimer to complete?

I have TFrame (fraDisplay) with TTimer (timAnimateDataChange). A timer is used to control small animations. In the form containing the frame, I want to have a method that does something like this:

procedure TForm.DoStuff;
begin
   DoSomeLogicStuff;
   fraDisplay.AnimateResult;
   WaitForAnimationToFinish;
   DoSomeOtherLogicStuff;
   fraDisplay.AnimateEndResult;
   WaitForAnimationToFinish;
   fraDisplay.Finalize;
end;

An animation is basically a TImage32 redraw synchronized by a timer. The timer will turn it off when finished, and the frame has the boolean property AnimationRunning, which will be set to false when the animation is complete.

There is no thread or anything like that to complicate or help.

The question is how to implement the WaitForAnimationToFinish method?

(Btw, this is a bad solution:

procedure TForm.WaitForAnimationToFinish;
begin
  repeat 
    Application.ProcessMessages;
  until not fraDisplay.AnimationRunning;
end;

since the timer does not work when the method starts :-()

+3
5

Smasher Delphi 2009.

procedure TForm.DoStuff;
begin
  DoSomeLogicStuff;
  fraDisplay.AnimateResult.OnFinished := 
    procedure (Sender: TObject)
    begin
      DoSomeOtherLogicStuff;
      fraDisplay.AnimateEndResult.OnFinished := 
        procedure (Sender: TObject)
        begin
          fraDisplay.Finalize;
        end;
      fraDisplay.AnimateEndResult;
    end;
  fraDisplay.AnimateResult;
end;

BTW: , WaitForAnimationToFinish OnTimer, Windows, ProcessMessages. , , .

+2

AnimationRunning False, , .

+1

Delphi , - Active Sleep.

+1

, , - , ? GUI. :

( ), , GUI - , , , X ..

, DoStuff ; , - . , , .

; , :)

0
source

Make AnimateResults take the parameter of the method that will be called when this is done.

0
source

Source: https://habr.com/ru/post/1723609/


All Articles