I'm trying to use a single timer for multiple purposes by redefining the procedure attached to the OnTimer event.
So one procedure does a 3 second countdown and then displays "GO!" as such:
procedure TfScoreboard.CountDownClockTimer(Sender: Tobject);
begin
if ClockInterval >= 1 then
begin
countdown.Caption:=ClockInterval.Tostring;
CenterCountdown;
PlayCountDown;
dec(ClockInterval);
end
else
begin
GameClock.Enabled:=false;
countdown.Caption := 'GO!';
CenterCountdown;
if options.sounds[4] <> '' then PlayMediaFromFile(options.sounds[4]);
delay(1000);
end;
end;
And the other is a countdown clock with a variable duration set at runtime on the control form:
procedure TfScoreboard.GameClockTimer(Sender: Tobject);
begin
if options.timer.interval <= 0 then begin
// Handle time expired
countdown.Caption := 'TIME''S UP!';
countdown.font.Size := 150;
countdown.font.name := 'Segoe UI Black';
centercountdown;
PlayWAVFromFile(options.sounds[7]);
GameClock.Enabled:=false;
exit;
end;
if options.timer.interval <= options.timer.WarningPoint then begin
// Handle playing warning tick-tock
end;
countdown.Caption := GetTimerString(options.Timer.Interval);
CenterCountdown;
dec(options.timer.interval);
end;
The OnTimer event is changed depending on what procedure is using the timer by assigning it with OnTimer:=@procedure;
So what is happening is if I run either one individually they run as they should, but if I run one following the other it's almost as if both procedures are running .. the second one counts down by 2s and if I run it multiple times it gets faster so not sure.
I would attach the code but even without the sounds and stuff it's 14MB. If I need to post more of the code I can.
Rich