[Lazarus] Using Lazarus for non-graphical apps

Sven Barth pascaldragon at googlemail.com
Sat Dec 28 23:37:04 CET 2013


On 28.12.2013 22:07, Mark Morgan Lloyd wrote:
> Michael Van Canneyt wrote:
>> On Sat, 28 Dec 2013, Mark Morgan Lloyd wrote:
>>
>>> Can TThread.Synchronize() be used in a non-graphical program (i.e.
>>> invoked from a unix shell and interacting with the user by typed
>>> commands) or does it rely on some LCL magic in the main thread which
>>> can't easily be replicated?
>>
>> Synchronize relies on checksynchronize being called regularly from the
>> main thread.
>>
>> If you use readln() or so, then it's not useful.
>
> Thanks, I'm reading stdin directly with a tight timeout using fpselect
> so it sounds like I should be able to manage something.
>

There is also the event Classes.WakeMainThread (of type TNotifyEvent) 
which is executed if a thread calls Synchronize (and "Queue" in 2.7.1). 
This event can be used to trigger the execution of CheckSynchronize. 
Please note that WakeMainThread is executed in context of the calling 
thread while CheckSynchronize *must* be called from the main thread.
Since you are using fpselect you could use a pipe which is filled by 
WakeMainThread and wait on that as well.

Regards,
Sven




More information about the Lazarus mailing list