[fpc-pascal] Cannot get TFPTimer to work

Darius Blaszyk dhkblaszyk at zeelandnet.nl
Thu Dec 2 19:39:58 CET 2010


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.OnTimer:=@OnTimerExec;
  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.    




More information about the fpc-pascal mailing list