Hello all again.
I have a timer that sends a message every 5 mins.
IF a trade is taking place I want the timer to pause, and when trade exits continue timer where it left off.
I need this so the timer wont restart.
ie: timer runs for 4 mins 58 sec. and trade opens I dont want to stop timer then exit trade and restart timer essintially forcing a +10 min. interval between send.
Is there a way to pause the timer while trade is open and unpause the timer when trade exits?
Thank you.
Comments
: I have a timer that sends a message every 5 mins.
: IF a trade is taking place I want the timer to pause, and when trade
: exits continue timer where it left off.
:
: I need this so the timer wont restart.
: ie: timer runs for 4 mins 58 sec. and trade opens I dont want to
: stop timer then exit trade and restart timer essintially forcing a
: +10 min. interval between send.
:
: Is there a way to pause the timer while trade is open and unpause
: the timer when trade exits?
:
: Thank you.
:
You can set the OnTimer event to nil, when the starts and assign it back when the trade is finished. That's not really a pause, but you won't see any notifications.
: back when the trade is finished. That's not really a pause, but you
: won't see any notifications.
This will cause the timer to stop and when trade is finished will resume timer where it stoped at?
Should I just add a sleep loop until trade exits?
if trade()=true then
repeat sleep (1000)
until trade()=false
would this work?
: : back when the trade is finished. That's not really a pause, but you
: : won't see any notifications.
:
: This will cause the timer to stop and when trade is finished will
: resume timer where it stoped at?
:
: Should I just add a sleep loop until trade exits?
: if trade()=true then
: repeat sleep (1000)
: until trade()=false
:
:
: would this work?
If your using a TTimer, then it won't work, because that component is based on the windows buildin timer. You can either enable or disable it, but not pause it. If you disable it it won't run, but enabling it will make it start from 0 and not from the time it stopped.
If you use a TTimer to keep track of the seconds, and code a timer based on that, then it is possible. For example:
[code]
var
FiveMinutePausibleTimer: integer = 300;
procedure TForm1.Timer1OnTimer(Sender: TObject);
// Timer1.Interval must be 1 sec.
begin
if (FiveMinutePausibleTimer > 0) then
dec(FiveMinutePausibleTimer)
else if (FiveMinutePausibleTimer = 0) then
begin
RingTimer();
FiveMinutePausibleTimer := 300;
end;
end;
procedure TForm1.PauseResumeButtonClick(Sender: TObject);
begin
// Pause timer by making FiveMinutePausibleTimer negative
// Resume timer by making FiveMinutePausibleTimer positive
FiveMinutePausibleTimer := -FiveMinutePausibleTimer;
end;
procedure TForm1.RingTimer();
begin
// Actual timer alert code
ShowMessage('5 minutes have passed');
end;
[/code]