O wow, for Windows you can indeed remove the ProcessMessages in my simple_postmessage.zip. BUT... on Linux you DO need the ProcessMessages. Otherwise the lines in memo1 don't get displayed until ALL messages are handled !!!
erm that explanation doesn't make sense to me.
It wasn't an explanation. It was an observation. It also puzzles me why this is happening.
This is what's going on... (with my simple-example and no threads)
When running the loop with 20.000 postmessages
for p := 1 to 20000 do
begin
PostMessage(Self.Handle, LM_POST_MESSAGE, p, p);
Button1.Caption := IntToStr(p);
end;
In Windows you see the button-caption running up. In Linux it directly displays 20.000. So the Windows-messaging somehow seems to keep doing the Paint for your form (even in a tight loop, maybe because of the PostMessage). In Linux paint-handling is only performed AFTER this procedure.
Now for the post_message() procedure:
procedure TForm1.post_message(var Msg: TLMessage);
begin
Memo1.Lines.add('p = ' + IntToStr(Msg.wParam) + ' ' + IntToHex(Integer(sPtr),4));
//Application.ProcessMessages;
end;
In Windows the same happens. Without the ProcessMessages it can still paint the Memo1. So in Windows you see all the lines appear after each other. In Linux nothing seems to happen and the memo1 is only updated when ALL the post_messages are processed. Only if you use the ProcessMessages you'll see them appear sequentially.
So somehow under Windows there is a separate process which handles the messaging for handing the painting and it runs besides the "normal" PostMessages-handling. Under Linux all messages (paint and post etc) are handled sequentially so the painting of the form is only performed at the end when all post_messages are processed (or when you insert a ProcessMessages).
I hope I explained this clearly. But it demonstrates that the messaging-handling under Linux is way less advanced (or flexible) (?).
Is it linux or gtk? If compiled as a QT application does it have the same problem? I'm asking because I think that QT hsa its own message queue implementation that is similar with the windows message queue.
I used gtk (Debian, Lazarus 1.5 r48991M FPC 2.6.5 i386-linux-gtk 2)
Oh wait I have a 32bit linux now I can test my self!! Let me do that and get back to you.
You'll see for yourself what I meant by above "observation"
Note: B.T.W. All this is (probably) unrelated to the problem we're having when using PostMessage in a thread under Linux. I understand that SendMessage is a problem (because it is still executed in the thread which calls is, I checked this) but PostMessage should be handled differently and in the correct thread (I also checked this). But there is still a problem when using PostMessage in threads (when you use about 1000 to 1500 it crashes).