Recent

Author Topic: Is it possible to use a TFPTimer in the console of my Raspberry ZERO  (Read 1822 times)

pascalbythree

  • Sr. Member
  • ****
  • Posts: 264
Is it possible to use a TFPTimer in the console of my Raspberry ZERO with FPC 3.2.2 ? Or is it not supported ?

It does not seem to run and i did see a access violation or two.

Anybody Example code ?

Greets, Wouter

Of course it is working on a form, but now in the console.

Now i am doing this:

Code: Pascal  [Select][+][-]
  1. procedure TAppProgBench.FTimerTimer(Sender: TObject);
  2. begin
  3.   // log('Timer1Exec',yellow);  
  4. end;
  5.  

Code: Pascal  [Select][+][-]
  1.   //**************************************************************************************  
  2.  FTimer := TFPTimer.Create(nil);
  3.  FTimer.OnTimer := @FTimerTimer;
  4.  FTimer.Interval := 1000; // in milliseconds
  5.  FTimer.Enabled := True;        
  6.  FTimer.StartTimer;
  7.   //********
******************************************************************************

Anybody knows what to change ? Grtz W

 :-[

balazsszekely

  • Guest
Re: Is it possible to use a TFPTimer in the console of my Raspberry ZERO
« Reply #1 on: April 08, 2023, 01:56:41 pm »
@pascalbythree
Console applications don't have a message loop so TFPTimer won't work. Just start a worker thread and measure time with GetTickCount64. See attached project for more details. Let me know if it works on Raspberry.

pascalbythree

  • Sr. Member
  • ****
  • Posts: 264
Re: Is it possible to use a TFPTimer in the console of my Raspberry ZERO
« Reply #2 on: April 08, 2023, 03:32:07 pm »
YaY Yay YAy!  It got to work, again, thank you very much !  8-)

PS: Also on raspberry
« Last Edit: April 09, 2023, 06:25:26 pm by pascalbythree »

TRon

  • Hero Member
  • *****
  • Posts: 3623
Re: Is it possible to use a TFPTimer in the console of my Raspberry ZERO
« Reply #3 on: October 02, 2023, 10:13:21 am »
Small update for this thread (as it just happened that I stumbled upon it in search for something else).

GetMem's example works like a charm, however:

TFPTimer does work when you enable UseTimerThread which (pretty much unsurprisingly) creates a thread for you in the background without the need to do that manually. Ofc. it does require threads so if your platform requires it then do not forget to add your platform specific threads unit as first entry to your uses clause (don't worry though as the runtime library will explain that to you as well in case you forgot  :) ).
« Last Edit: October 02, 2023, 10:17:30 am by TRon »
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

 

TinyPortal © 2005-2018