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.
Re: how to count down from 30 seconds with a timer. 80 80

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.

Re: how to count down from 30 seconds with a timer. 80 80

Geeze - people are still using Pascal these days? Are you running a P-machine, or some version of Turbo Pascal? Ok. Better to use a timer interrupt instead of a constant loop, and if you need to do stuff before the timer kicks, then use a loop and check the bit as shown here: http://www.ibrtses.com/embedded/avrtimer.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.