How could one reset the TTimer1 so even ontimer triggers, and the count restarted?
The Question is for Design Time command to act on Run-time.
How could one reset the TTimer1 so even ontimer triggers, and the count restarted?
The Question is for Design Time command to act on Run-time.
I suppose you actually mean that
var
Timer1: TTimer;
Then, to reset the timer, do
Timer1.Enabled := false;
Timer1.Enabled := true;
In my "RejbrandCommon.pas" standard library, I have actually defined
procedure RestartTimer(Timer: TTimer);
begin
Timer.Enabled := false;
Timer.Enabled := true;
end;
Then, every time I need to restart I timer, I just do
RestartTimer(Timer1);
Of course, if you want the OnTimer
procedure (e.g. Timer1Timer
) to trigger prior to restart, you have to do
Timer1.OnTimer(Self);
Timer1.Enabled := false;
Timer1.Enabled := true;
or define
procedure TriggerAndRestartTimer(Timer: TTimer);
begin
Timer.OnTimer(nil);
Timer.Enabled := false;
Timer.Enabled := true;
end;
(Of course, the last procedure, TriggerAndRestartTimer
, is not a method, and hence there is no Self
. However, most likely the Timer1Timer
procedure doesn't care about the Sender
property, so you can send just anything, such as nil
instead of Self
.)
There's no way to do it in design time. Have the handler disable the TTimer
then re-enable it.