0

I'm trying to work out how I can call a timer with a variable. I'd like to code it more efficiently than write the same code multiple times when I could just call the one timer but with a variable name. All these timers will run the same process, run for x many mins depending on the number of minutes between start and end. For example:

I'd like to run a set of commands using timer(i) where (i) is passed as a selection from a list rather than: if (i) = 1 Timer1.active := True: if (i) = 2 Timer2.active := True; etc.etc. The thing is the number of items on the list can vary as it is set elsewhere in the code.

Sorry if this seems like a dumb question but when I was teaching I always told my classes there is no such thing as a dumb question. Thanks in advance.

Swagman9203
  • 21
  • 1
  • 2
  • 2
    put your timers in an array, the index(-1) is the timer you want... – whosrdaddy Feb 05 '20 at 07:38
  • Awesome, thanks for the quick response – Swagman9203 Feb 05 '20 at 10:45
  • You could also use a modified list that has his Add method overriden so that a timer is created each time a item is added. And store the timer in the associated object in the list. – fpiette Feb 05 '20 at 14:48
  • Are we talking here about repeating commands or list of commands that will fire once sometime in the future. If it is former than using array of times might do the trick. But if it is the latter then it might be better to use just one timer with short interval which then executes a routine which checks your list to see if some action needs to be executed already. Note that each action on your list also needs to contain timestamp marking its expected execution time. I would also recommend that this list is ordered by the mentioned timestamp so you don't have to iterate through every item. – SilverWarior Feb 05 '20 at 19:51

0 Answers0