[fpc-devel] procedure ... message(); in Linux

Graeme Geldenhuys graemeg.lists at gmail.com
Thu Feb 18 09:21:03 CET 2010


I hope I understand your question correctly...


Michael Schnell wrote:
> What messages does it capture ?

Anything that fits into 'var message' parameter. fpGUI uses the following
base structure for the event queue.

  TfpgMessageRec = record
    MsgCode: integer;
    Sender: TObject;
    Dest: TObject;
    Params: TfpgMessageParams;
    Stop: Boolean;
  end;



> How to send a message from a thread ?

fpGUI has an internal event queue which later gets dispatched to the target
using TObject.Dispatch(). fpGUI v0.4 and earlier used a Object based even
system and had it's own distribution functions. Later version of fpGUI uses
Record based messages and the 'message' language feature of Object Pascal.

fpGUI has the following procedures defined in fpg_main.pas unit that work
with the message queue.

procedure fpgPostMessage(Sender, Dest: TObject; MsgCode: integer; var
aparams: TfpgMessageParams); overload;
procedure fpgPostMessage(Sender, Dest: TObject; MsgCode: integer); overload;
procedure fpgSendMessage(Sender, Dest: TObject; MsgCode: integer; var
aparams: TfpgMessageParams); overload;
procedure fpgSendMessage(Sender, Dest: TObject; MsgCode: integer); overload;
procedure fpgDeliverMessage(var msg: TfpgMessageRec);
procedure fpgDeliverMessages;


Here is an example of the X11 backend in fpGUI translating the X11 window
messages into fpGUI messages and dispatching them to the message queue.

--------------------------------------
    X.FocusIn:
        fpgPostMessage(nil, FindWindowByHandle(ev.xfocus.window),
            FPGM_ACTIVATE);

    X.FocusOut:
        fpgPostMessage(nil, FindWindowByHandle(ev.xfocus.window),
            FPGM_DEACTIVATE);

    X.EnterNotify:
        fpgPostMessage(nil, FindWindowByHandle(ev.xcrossing.window),
            FPGM_MOUSEENTER);

    X.LeaveNotify:
        fpgPostMessage(nil, FindWindowByHandle(ev.xcrossing.window),
            FPGM_MOUSEEXIT);
--------------------------------------

All the above describes messages from main thread to component or thread to
component.

For one thread to another thread, I would imagine a simple thread-safe
message queue could be created (a simple list with message items). I'm not
sure if FPC supplies a thread-safe list class. Each thread will
periodically check the queue for messages related to itself, or post
messages for other threads. A multi-read-single-write synchronizer
(available in FPC as TMultiReadExclusiveWriteSynchronizer) could be used
when accessing the message queue.



> How to send a message from another process ?


On example would be to use IPC as defined in the SimpleIPC unit - part of
FCL. SimpleIPC documentation can be found at:

  http://www.freepascal.org/docs-html/fcl/simpleipc/index.html

You can obviously use other custom communications methods too.



Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/




More information about the fpc-devel mailing list