Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-09

PostMessage vs. QueueAsyncCall

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Xiangrong Fang

Hi,

In a previous email asking about PostMessage, Michael suggested I used QueueAsyncCall instead, because although it's OK to use PostMessage, but it is considered a Windows Legacy, or only for Delphi compatibility.

However, in actual use, I feel that PostMessage does a better job for code separation. Because when use PostMessage, GUI (or main thread) related code are written in the main form, and the thread will not need to use the Forms unit.

My question is, why cannot Lazarus just use PostMessage, but invent the QueueAsyncCall() method? What is the rationale, or, why PostMessage is considered windows-ish (read: not fit into LCL very well?), apart from the fact that it is a Windows API?

Thanks,
Xiangrong

Reply by email

Michael Schnell
to Xiangrong Fang
Xiangrong Fang wrote
Hi, In a previous email asking about PostMessage, Michael suggested I used QueueAsyncCall instead,

In fact now that I know what you are trying to accomplish (a Thread Pool) I take back the suggestion of QueueAsyncCall, as same is supported by Lazarus (LCL) and not directly by fpc (RTL). As I feel that a ThreadPool should be working independently of the GUI, I would use TThread.Synchronize or TThread.Queue.

In fact I did a TThreadPool component that works nicely for me. This is discussed in the Lazarus Forum (even though I think it should better be discussed here, as it does not use any Lazarus features.

My question is, why cannot Lazarus just use PostMessage, but invent the QueueAsyncCall() method?

Windows is a "Message driven" OS. This might be nice but other OSes don't support or force this paradigm.

As fpc is supposed to be as portable as possible, it can't work "Message driven" under the hood, which is not supported by other OSes.

To support Code ported from Delphi, "PostMessage" is provided by Lazarus in the LCL (but AFAIK, not by fpc, which can be used without Lazarus / LCL)

-Michael

Reply by email

Mattias Gaertner
to Xiangrong Fang: In a previous email asking about PostMessage, Michael suggested I used QueueAsyncCall…
Show quoted text 5 lines
[...] My question is, why cannot Lazarus just use PostMessage, but invent the QueueAsyncCall() method? What is the rationale, or, why PostMessage is considered windows-ish (read: not fit into LCL very well?), apart from the fact that it is a Windows API?

Please ask Lazarus question on the Lazarus lists.

PostMessage is a WinAPI function that sends an uint, and two pointer sized integers to a Windows Handle with a queue, even to another process. See here:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644944%28v=vs.85%29.aspx

The LCL emulates some parts of PostMessage on other widget sets.

TApplication.QueueAsyncCall on the other side allows to call a method in the main thread with an optional data pointer. And the call can be removed from the queue.

Mattias

Reply by email