On Mon, 7 Sep 2020, Bo Berglund via fpc-pascal wrote:

Ì 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?

Do you call checksynchronize at regular intervals ? The default timer is
threaded, and the OnTimer event is called in the main thread. For this to
work, you need to call checksynchronize at regular intervals in your main
thread.

Michael.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to