[fpc-pascal] TFPTimer does not fire, why?

Bo Berglund bo.berglund at gmail.com
Mon Sep 7 11:36:01 CEST 2020


Ì have a problem using TFpTimer on Linux (FPC 3.0.4, Lazarus 2.0.8 on
Raspbian).

The application is a small GUI test app where I have added a timer in
order to update the display with incoming data.
So I have it set up like this:

{$mode Delphi}
interface
uses
  ...
  fptimer,
  ...
type

  TfrmMain = class(TForm)
  ...  
  private
    FTimCheckInputs: TFpTimer;
  ...
    procedure OnTimCheckInputs(Sender: TObject);
  ...

implementation

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  ...
  FTimCheckInputs := TFpTimer.Create(NIL);
  FTimCheckInputs.OnTimer := OnTimCheckInputs;
  FTimCheckInputs.Interval := 500; // 500 ms latency
  ...
end;

procedure TfrmMain.OnTimCheckInputs(Sender: TObject);
begin
  ShowInByte; //<== This is NEVER reached!
end;

procedure TfrmMain.btnOpenComClick(Sender: TObject);
begin
  ...
  if FRemote.OpenPort(edComPort.Text, StrToInt(cbxBaud.Text)) then
  begin
    ...
    FTimCheckInputs.Enabled := true;
  end
  else
  begin
    ...
    FTimCheckInputs.Enabled := false;
  end;
end;

procedure TfrmMain.FormClose(Sender: TObject; var CloseAction:
TCloseAction);
begin
  FTimCheckInputs.Enabled := false;
  FTimCheckInputs.Free;
  ...
end;

When I click the btnOpenCom button I get to the button event and the
code reachers the line:

  FTimCheckInputs.Enabled := true;

So presumably here the timer should start and fire after 500 ms as set
up in the FormCreate procedure.
But it never does! I do not get into this at all. I have put a
breakpoint there but it never fires, whereas other breakpoints do fire
so I can see that for example btnOpenComClick fires off properly and
the timer should be enabled.

And before you ask, I *have* this at the beginning of the lpr file:
uses
  {$IFDEF UNIX}
  cthreads, 
  {$ENDIF}


Why does the FpTimer event not fire?
I am assuming the Interval property is in milliseconds...

When I step through the code and reach the place where the timer is
enabled the text that appears when I hover over the Enabled keyword is
very strange:

"FTimCheckInputs.Enabled = TYPE FPTIMER has no component named
ENABLED.
published property TFPTimer.Enabled:Boolean"

Is it not possible to start the timer using Enabled?????


-- 
Bo Berglund
Developer in Sweden



More information about the fpc-pascal mailing list