Recent

Author Topic: [SOLVED] Timer in a linux console  (Read 12186 times)

vexal

  • New Member
  • *
  • Posts: 29
[SOLVED] Timer in a linux console
« on: August 25, 2011, 02:06:50 pm »
Hi !

I implemented a TTimer in a crossplatform console application.
Under Windows, i made a infinite loop that process messages for TTimer with this code :

Code: [Select]
procedure ProcessMessages;
var
  Msg: TMsg;
begin
  while PeekMessage(Msg, 0, 0, 0, PM_REMOVE) do begin
    if Msg.Message <> WM_QUIT then begin
      TranslateMessage(Msg);
      DispatchMessage(Msg);
    end else
      exit;
  end;
end;

But under Linux, i cannot make it work because TranslateMessage and DispatchMessage are in the windows unit.

Do you know how i can do ?
« Last Edit: September 02, 2011, 10:49:16 am by vexal »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Timer in a linux console
« Reply #1 on: August 25, 2011, 06:17:45 pm »
LCL's TTimer is already cross platform. You can use it from console apps by selecting NoGUI widgetset. Or directly use TFPTimer instead.

vexal

  • New Member
  • *
  • Posts: 29
Re: Timer in a linux console
« Reply #2 on: August 26, 2011, 10:19:03 am »
Thank you !

I tried with tfptimer but it is the same, my "timer" function is never called.

I tried with nogui widgetset but i get an exception : No timers available

(Lazarus 0.9.30 x64 CentOs 6)

vexal

  • New Member
  • *
  • Posts: 29
Re: Timer in a linux console
« Reply #3 on: August 26, 2011, 10:31:43 am »
I add checkSynchronize in my infinite loop and it works well now with fptimer :
Code: [Select]
while true do
  begin
    checkSynchronize;
    sleep(10);
  end;

Thank you very much ! :)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: [SOLVED] Timer in a linux console
« Reply #4 on: August 26, 2011, 11:11:12 am »
Glad to know that. I don't know what's wrong with your way of using TFPTimer (since you didn't post any code), but just ensure you have its Enabled property set to true, Interval to some milliseconds and OnTimer with the handler correctly.

vexal

  • New Member
  • *
  • Posts: 29
Re: [SOLVED] Timer in a linux console
« Reply #5 on: September 02, 2011, 10:00:08 am »
I am using fptimer and it works (with checkSynchronize) but only if i compile with gtk2 widgetset under linux and win32 widgetset under windows.
My program will work in a linux system (centos 6 minimal) without any gui (no xwindow).
If i want to compile it with the nogui widgetset, the compilation is ok but when i execute it, i have the message :
Quote
exception at 00000000006781A7:
No timer available.
Is it because the the fptimer is not implemented in the nogui widgetset ?
« Last Edit: September 02, 2011, 10:09:11 am by vexal »

vexal

  • New Member
  • *
  • Posts: 29
Re: [SOLVED] Timer in a linux console
« Reply #6 on: September 02, 2011, 10:53:09 am »
Sorry, the exception was due to a ttimer left in my code in a "deep" function.
The fact it works with some widgetset and not the nogui is odd anyway.
Thank you

 

TinyPortal © 2005-2018