[lazarus] GTK message handlers.

michael at tfdec1.fys.kuleuven.ac.be michael at tfdec1.fys.kuleuven.ac.be
Sun Apr 25 14:47:09 EDT 1999


As requested by Michael Zayats, we've implemented some changes to support 
messages from GTK more directly. 

The implementation of it is as follows:

Declare a message handler with SELF as one of the paameters.

Procedure TMyClass.MyMessageHandler (Arg1 : Type1; Arg2 : Type2;
                                     Self : TMyClass;
                                     Argn : Typen); message 'themessage';cdecl;

What happens is the following: For string message handlers, you can specify
SELF as one of the parameters. The compiler will then load this parameter in
the SELF register of the class. 
The type of SELF must be the same as the type of the class, or an error 
will occur. It is also only possible for 'string' message handlers.

This means that you can do for instance:

Procedure TMyDangerButton.FormatHarddrive (Widget : PGtkWidget; 
                                           Self : TMyDangerButton);message 'clicked'; cdecl;


Procedure TMyDangerButton.Create()

  // Create the GTK button widget
  // Connect to onclick handler, pass self as data.
  // No way to avoid the ugly typecast... This is Pascal, after all..

So no global dispatching functions or whatever are needed.

This has been put in the compiler, but not yet tested or committed to CVS,
although the generated code looks OK.

I will notify when it has been committed and tested.


More information about the Lazarus mailing list