Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-02

Having trouble getting fptimer to work in a Daemon.

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Joshua Lim

Hi,

I'm a pascal newbie, after spending some time getting a daemon to work, I now have trouble getting a timer to work. I was recommended to use TFPTimer from the fpTimer unit - http://mantis.freepascal.org/view.php?id=14118&nbn=5

I tried the following code but the OnTimer doesn't trigger. There are no errors either. Grateful for any pointers. :)

uses
fpTimer;
...
 TDaemon1 = class(TDaemon)
....
private
.....
public
    procedure FTimerTimer( Sender : TObject );
.....
var
  Daemon1: TDaemon1;
  FTimer : TFPTimer;
.....
procedure TDaemon1.FTimerTimer( Sender : TObject );
var
...
 BEGIN
....
END;
procedure TDaemon1.DataModuleStart(Sender: TCustomDaemon; var OK: boolean);
var
...
begin
 FTimer := TFPTimer.Create(nil);
 FTimer.OnTimer := @FTimerTimer;
 FTimer.Interval := 1000; // in milliseconds
 FTimer.Enabled := True;
 FTimer.StartTimer;

Note: I've also posted here - http://lazarus.freepascal.org/index.php/topic,8615.0.html

_________________________________________________________________ Hotmail: Free, trusted and rich email service.
https://signup.live.com/signup.aspx?id=60969
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20100215/352ce32e/attachment.html>

Reply by email

Michael Van Canneyt
to Joshua Lim
Joshua Lim wrote
Hi, I'm a pascal newbie, after spending some time getting a daemon to work, I now have trouble getting a timer to work. I was recommended to use TFPTimer from the fpTimer unit - http://mantis.freepascal.org/view.php?id=14118&nbn=5

The standard driver for fpTimer is not suitable for use in a daemon application, as the timer events are only triggered in the main thread, and each daemon runs in its own thread.

Michael.

Show quoted text 42 lines
I tried the following code but the OnTimer doesn't trigger. There are no errors either. Grateful for any pointers. :) uses fpTimer; ... TDaemon1 = class(TDaemon) .... private ..... public procedure FTimerTimer( Sender : TObject ); ..... var Daemon1: TDaemon1; FTimer : TFPTimer; ..... procedure TDaemon1.FTimerTimer( Sender : TObject ); var ... BEGIN .... END; procedure TDaemon1.DataModuleStart(Sender: TCustomDaemon; var OK: boolean); var ... begin FTimer := TFPTimer.Create(nil); FTimer.OnTimer := @FTimerTimer; FTimer.Interval := 1000; // in milliseconds FTimer.Enabled := True; FTimer.StartTimer; Note: I've also posted here - http://lazarus.freepascal.org/index.php/topic,8615.0.html _________________________________________________________________ Hotmail: Free, trusted and rich email service. https://signup.live.com/signup.aspx?id=60969

Reply by email

Joshua Lim

Hi Michael, thanks, is there a work around solution to simulating a trigger in a Lazdaemon?

Rgds,
Joshua

From: Michael Van Canneyt
The standard driver for fpTimer is not suitable for use in a daemon application, as the timer events are only triggered in the main thread, and each daemon runs in its own thread.

Michael.

Earlier message 61 lines
From: joshua__lim To: Subject: Having trouble getting fptimer to work in a Daemon. Date: Mon, 15 Feb 2010 10:02:48 +0000 Hi, I'm a pascal newbie, after spending some time getting a daemon to work, I now have trouble getting a timer to work. I was recommended to use TFPTimer from the fpTimer unit - http://mantis.freepascal.org/view.php?id=14118&nbn=5 I tried the following code but the OnTimer doesn't trigger. There are no errors either. Grateful for any pointers. :) uses fpTimer; ... TDaemon1 = class(TDaemon) .... private ..... public procedure FTimerTimer( Sender : TObject ); ..... var Daemon1: TDaemon1; FTimer : TFPTimer; ..... procedure TDaemon1.FTimerTimer( Sender : TObject ); var ... BEGIN .... END; procedure TDaemon1.DataModuleStart(Sender: TCustomDaemon; var OK: boolean); var ... begin FTimer := TFPTimer.Create(nil); FTimer.OnTimer := @FTimerTimer; FTimer.Interval := 1000; // in milliseconds FTimer.Enabled := True; FTimer.StartTimer; Note: I've also posted here - http://lazarus.freepascal.org/index.php/topic,8615.0.html Hotmail: Free, trusted and rich email service. Get it now. _________________________________________________________________ Hotmail: Free, trusted and rich email service. https://signup.live.com/signup.aspx?id=60969 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20100219/3bd7e065/attachment.html>

Reply by email

Adrian Veith
to Joshua Lim

the problem is, that a normal thread does not have a message queue. You can create a second thread, which calls some method in a periodic cycle and sleeps in between. But you must take care, that this thread is synchronized to your daemon thread.

Adrian.

Joshua Lim wrote 85 lines
Hi Michael, thanks, is there a work around solution to simulating a trigger in a Lazdaemon? Rgds, Joshua ------------------------------------------------------------------------ From: *Michael Van Canneyt* The standard driver for fpTimer is not suitable for use in a daemon application, as the timer events are only triggered in the main thread, and each daemon runs in its own thread. Michael. ------------------------------------------------------------------------ From: joshua__lim To: Subject: Having trouble getting fptimer to work in a Daemon. Date: Mon, 15 Feb 2010 10:02:48 +0000 Hi, I'm a pascal newbie, after spending some time getting a daemon to work, I now have trouble getting a timer to work. I was recommended to use TFPTimer from the fpTimer unit - http://mantis.freepascal.org/view.php?id=14118&nbn=5 I tried the following code but the OnTimer doesn't trigger. There are no errors either. Grateful for any pointers. :) uses fpTimer; ... TDaemon1 = class(TDaemon) .... private ..... public procedure FTimerTimer( Sender : TObject ); ..... var Daemon1: TDaemon1; FTimer : TFPTimer; ..... procedure TDaemon1.FTimerTimer( Sender : TObject ); var ... BEGIN .... END; procedure TDaemon1.DataModuleStart(Sender: TCustomDaemon; var OK: boolean); var ... begin FTimer := TFPTimer.Create(nil); &nbs p;FTimer.OnTimer := @FTimerTimer; FTimer.Interval := 1000; // in milliseconds FTimer.Enabled := True; FTimer.StartTimer; Note: I've also posted here - http://lazarus.freepascal.org/index.php/topic,8615.0.html ------------------------------------------------------------------------ Hotmail: Free, trusted and rich email service. Get it now. <https://signup.live.com/signup.aspx?id=60969> ------------------------------------------------------------------------ Hotmail: Free, trusted and rich email service. Get it now. <https://signup.live.com/signup.aspx?id=60969> -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20100219/84e75567/attachment.html>

Reply by email