[fpc-pascal] Timers in FPC

Michael Van Canneyt michael at freepascal.org
Thu May 31 15:57:46 CEST 2007



On Thu, 31 May 2007, Graeme Geldenhuys wrote:

> > > I guess I'm a bit late in asking, seeing that I already implemented by
> > > own thread based timer. I works 100% for what I need. I just wondered
> > > if there was something like that built into FPC that I missed.  I
> > > would like to compare the implementations, or share mine if FPC
> > > doesn't have one.
> >
> > You're welcome to share yours.
> >
> > Michael.
> 
> 
> Hopefully somebody could find this useful or possibly it could find
> its way into FPC and be the beginnings of a basic timer in FPC.  Why
> must everybody always reinvent the wheel.  :-)

Thanks. I had a quick look.

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 ?

This would allow the LCL to implement a TTimerDriver descendent
which integrates nicely in the LCL. The actually used driver is 
set through some global class variable. And at the same time
there is already a default driver available for all platforms.

Michael.
> 
> See attached file: threadtimer.pas
> 
> Usage:
> -----------
> 
>  FTimer := TFPTimer.Create(nil);
>  FTimer.OnTimer      := @FTimerTimer;
>  FTimer.Interval     := 500;  // in milliseconds
>  FTimer.Enabled      := False;
> 
> You can then call functions like:
> FTimer.On;
> FTimer.Off;
> FTimer.Enabled := False;
> 
> 
> -- 
> Graeme Geldenhuys
> 
> General error, hit any user to continue.
> 



More information about the fpc-pascal mailing list