[fpc-pascal] Timers in FPC

Michael Van Canneyt michael at freepascal.org
Thu May 31 16:31:52 CEST 2007



On Thu, 31 May 2007, Graeme Geldenhuys wrote:

> On 5/31/07, Michael Van Canneyt <michael at freepascal.org> wrote:
> >
> > Do you mind if I split up the implementation like this:
> >
> > TTimer               - Exposes all needed properties, events. Delegates work
> > to TTimerDriver.
> > TTimerDriver         - Abstract class which has 2 methods and a property to
> > do the actual work.
> > TThreadedTimerDriver - TTimerDriver Descendent which uses your
> > implementation to do the actual work.
> >
> > and then I add this to the FCL as unit fpTimer ?
> 
> No problem, that's fine by me....
> 
> 
> > This would allow the LCL to implement a TTimerDriver descendent
> > which integrates nicely in the LCL. The actually used driver is
> 
> Would you mind explaining this a bit more?  What would the LCL do
> differently, "integrates nicely"?

Instead of using the default timer which creates a thread, it can create 
a TTimerDriver which asks e.g. MS-Windows for a timer event and handle 
everything through the event loop. Same for X11 (or however they do it there). 

In other words, the LCL can use system timers if available, and integrate 
them with the normal event loop. I think this is preferable to threaded 
timers, which make applications heavier.

Also, you could improve the threaded timer with a pooled threaded timer
(1 thread which does the work for all timers). If you use a lot of timers,
that will be easier on resources.

Michael.





More information about the fpc-pascal mailing list