Dear Delphi programmers,
I’m looking for help how to write a one-shot timer (No GUI, so VCL Timers out of question)…
Let me explain a little bit more.
In my code (explaining with VCL timer but in this particular project I have no forms):
- Call a
procedurewhich send a char over serial port - Enable a timer with a X amount of
Interval
In the OnTimer event:
I have a code which send a char then disable the timer itself to never be executed again.
The problem is that I need to make the creation of these timers dynamic.
I thought of the function SetTimer() then KillTimer() in the “OnTimer event” to disable it (free it).
Is it a good (safe) way?
Thank you!
Is it safe to kill timer from inside of a timer event ?
Yes, that’s perfectly safe.
How to implement simplest one shot timer ?
The easiest implementation of a 1 second one shot timer is this, but note, that if you start more of them, you won’t be able to distinguish which one of them elapsed its interval: