Sign in Join

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

Mailing lists / fpc-pascal / 2010-12

Cannot get TFPTimer to work

5 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

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

Darius Blaszyk

Whatever I tried, I cannot get TFPTimer to work. Can someone help? For some reason the OnTimer even is never fired. Tried on Windows and Linux. Here's a snippet I used as test.

Regards, Darius

program fptimertest;
{$mode objfpc}{$H+}
uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils, fpTimer;
type
  { TBaseObj }
  TBaseObj = class(TObject)
     tmr: TFPTimer;
  public
     constructor Create;
     constructor Destroy;
     procedure OnTimerExec(Sender: TObject);
  end;

{ TBaseObj }

constructor TBaseObj.Create;
begin
  tmr := TFPTimer.Create(nil);
  tmr.Interval := 1;
  ;
  tmr.StartTimer;
end;
constructor TBaseObj.Destroy;
begin
  tmr.StopTimer;
  tmr.Free;
end;
procedure TBaseObj.OnTimerExec(Sender: TObject);
begin
  writeln('Timer executed');
end;
var
  test: TBaseObj;
  i: integer;
begin
  test := TBaseObj.Create;
  for i := 1 to 1000 do
    sleep(10);
  writeln('done');
  readln;
end.
Burkhard Carstens
to Darius Blaszyk
Darius Blaszyk wrote 6 lines
Whatever I tried, I cannot get TFPTimer to work. Can someone help? For some reason the OnTimer even is never fired. Tried on Windows and Linux. Here's a snippet I used as test. Regards, Darius

[..]

begin test := TBaseObj.Create; for i := 1 to 1000 do
begin
sleep(10);
checkSynchronize;
end;
writeln('done'); readln; end.

Isn't OnTimerExec called using Synchronize?

Michael Van Canneyt
to Burkhard Carstens
Burkhard Carstens wrote 27 lines
Am Donnerstag, 2. Dezember 2010 19:39 schrieb Darius Blaszyk: > Whatever I tried, I cannot get TFPTimer to work. Can someone help? > For some reason the OnTimer even is never fired. Tried on Windows and > Linux. Here's a snippet I used as test. > > Regards, Darius > [..] > begin > test := TBaseObj.Create; > for i := 1 to 1000 do begin > sleep(10); checkSynchronize; end; > > writeln('done'); > readln; > end. Isn't OnTimerExec called using Synchronize?

Yes.

Michael.

Brian Winfrey
to Darius Blaszyk: Whatever I tried, I cannot get TFPTimer to work. Can someone help? For some reason the…

See .../fpcsrc/packages/fcl-base/examples/testtimer.pp for example usage.

Darius Blaszyk wrote 68 lines
Whatever I tried, I cannot get TFPTimer to work. Can someone help? For some reason the OnTimer even is never fired. Tried on Windows and Linux. Here's a snippet I used as test. Regards, Darius program fptimertest; {$mode objfpc}{$H+} uses  {$IFDEF UNIX}  cthreads,  {$ENDIF}  SysUtils, fpTimer; type  { TBaseObj }  TBaseObj = class(TObject)     tmr: TFPTimer;  public     constructor Create;     constructor Destroy;     procedure OnTimerExec(Sender: TObject);  end; { TBaseObj } constructor TBaseObj.Create; begin  tmr := TFPTimer.Create(nil);  tmr.Interval := 1;  ;  tmr.StartTimer; end; constructor TBaseObj.Destroy; begin  tmr.StopTimer;  tmr.Free; end; procedure TBaseObj.OnTimerExec(Sender: TObject); begin  writeln('Timer executed'); end; var  test: TBaseObj;  i: integer; begin  test := TBaseObj.Create;  for i := 1 to 1000 do    sleep(10);  writeln('done');  readln; end. _______________________________________________ fpc-pascal maillist  -   http://lists.freepascal.org/mailman/listinfo/fpc-pascal