am looking for a way to count down from 30 seconds using a timer and updating a Gauge using Progress to reflect the time remaining.
I know this is very simple code but my brain is some what dead here my bad code.

procedure FreeTimerTimer(Sender: TObject);
begin
  TotalTime := GetTickCount() - FreeTimer.Interval; // 30000 int
  //
  Gauge.MaxValue := 100;
  Gauge.MinValue := 0;
  Gauge.Progress := TotalTime;
  //
  if Gauge.Progress = 100 then
  begin
      FreeTimer.Enabled := False; // stop timer when done
  end;
end;

Thanks.

The GetTickCount function retrieves the number of milliseconds that have elapsed since the system was started, up to 49.7 days
Your comment suggests FreeTimer.Interval is 30000.
So you set TotalTime, and hence the gauge progress, to the number of milliseconds that have elapsed since the system was started, less 30000. For your gauge to work, Gauge.Progress must be between Gauge.MinValue (0) and Gauge.MaxValue (100). This is only true for 1 tenth of a second every 49.7 days. Probably not what you want.

I suggest you set Gauge.MaxValue to 30000. Use a CountdownStarted variable and set this to GetTickCount whenever the countdown starts. Your timer event should again call GetTickCount and subtract CountdownStarted from this. That will be the number of milliseconds since the countdown started and you can use this for Gauge.Progress.

This article has been dead for over six months. Start a new discussion instead.