Recent

Author Topic: creating multiple downcounter  (Read 1577 times)

Stygian

  • Jr. Member
  • **
  • Posts: 90
creating multiple downcounter
« on: January 26, 2015, 09:25:09 am »
Hello Everyone,

I want to create 6 downcounter which are count down from a cauculated time(all different). The TTimer is not so usable here because they will "interrupt" at the same time(1000ms) and "kill" each other timing and I'm not start all the countdown in the same time so i can't use only one. Is this any good option for this?

Thanks,
Sty

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: creating multiple downcounter
« Reply #1 on: January 26, 2015, 11:56:03 am »
You can still do that with just 1 TTimer, but you need to set it use the minimum allowed interval. Some code:
Code: [Select]
type
  TPeriodicEvent = record
    ticks, current: integer;
    name: string;
    // Add maybe a pointer to procedure?
  end;
...
  events: array of TPeriodicEvent;
...
procedure TForm1.Timer1Timer(Sender: TObject);
var e: integer;
begin
  for e:=0 to high(events) do
    with events[e] do begin
      inc(current);
      if current >= ticks then begin
        current:=0;
        // Do something...

      end;
    end;
end;
You can for example set the interval to 100, so if you want to run 1 event every 1 second, you set its ticks to 10. Ticks 0 or 1 will run every time. (if i'm thinking this right...) But you can have any number of timers, and start them at different times.

 

TinyPortal © 2005-2018