[Lazarus] What to replace Application.Processmessages with?

Bo Berglund bo.berglund at gmail.com
Tue Oct 13 11:29:06 CEST 2020


(Tried posting this via GMane but it does not appear so now sending email instead)

 

I have been working some time to convert a rather big Delphi2007 Windows service application to a regular Linux program possible to run as a Linux systemd service.

In Linux I was told that the application needs to be a regular program to run in a non-logged on setting on a Linux server (without desktop).

 

So I have come a long way now and it feels like i am in the final stretch.

All of the TCP/IP socket communications to a client config app and handling of serial ports and digital I/O has been solved.

The program runs OK at its core as a non-gui app and I can use the existing client application on Windows to talk to it and configure the system etc.

 

But now when I approach the actual core of the service, the ability to run a longish task on external hardware while still being able to handle incoming client requests etc I have found a possible problem...

 

The original server on Windows was built as a TService application and had the GUI support maybe via a Delphi data module or otherwise so the Application object is available.

I had to change this to a simple program instead and so I lost the Application object.

 

In a lot of places in the task execution code there are Application.Processmessages in wait loops and these I had to switch off via a conditional named GUI_MODE and instead I have a sleep(T) call there. Example:

 

while FContactResTestRunning and not FCancelOp do

  begin

    {$IFDEF GUI_MODE}

      Application.ProcessMessages;

    {$ENDIF}

    Sleep(50);

  end;

 

Here the booleans FContactResTestRunning and FCancelOp are supposed to be set in the main application on reception of certain events.

 

NOTICE:

The class file where all of this is coded is also used in a GUI application on Windows where the user communicates with the instrumentation manually from the app. In that setting Application is available and all works well.

 

The service application itself (from 2004) is based on timers to perform things like execution of the measurement task itself in order to isolate that from the main application. That is why there is Application.Processmessages inside the wait loops so that things like reception of RS232 messages from the equipment can be handled and analyzed and flags be set which are waited for in the timer...

 

The TTimer objects have been replaced by TFpTimer objects in the ported code and this seems to work fine, whereas TTimer does not.

 

I know that the system should have been designed using threads instead, but that is not there and it is probably a too difficult project to try and replace the current structure with threads.

 

Now I wonder if I could put something else into the loops so that the main object of Application.Processmessages will be handled, namely to let event functions run as needed.

Can I for example use CheckSynchronize in these loops?

 

I.e. Application.Processmessages ==> CheckSynchronize?

 

Or is there any other way?

 

/Bo B, Sweden

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20201013/d194e509/attachment.html>


More information about the lazarus mailing list