Sign in Join

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

Mailing lists / lazarus / 1999-04

GTK message handlers.

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Unknown author

Hello,

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;
begin
  FormatDisk('C:');
end;
Procedure TMyDangerButton.Create()
begin
  // Create the GTK button widget
  // Connect to onclick handler, pass self as data.
  gtk_signal_connect(gtk_Object(fcomponent),
                     'clicked',
                     gtk_Signal_Func(@FormatHardDrive),
                     Self);
  // No way to avoid the ugly typecast... This is Pascal, after all..
end;

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.

Michael.

Cliff Baeseman
to Unknown author

Shane what do you think about this? I think we should leave our current form of events in place for now since it seems to work very well.

What are yur thoughts on this.

Cliff

Show quoted text 53 lines
Hello, 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; begin FormatDisk('C:'); end; Procedure TMyDangerButton.Create() begin // Create the GTK button widget // Connect to onclick handler, pass self as data. gtk_signal_connect(gtk_Object(fcomponent), 'clicked', gtk_Signal_Func(@FormatHardDrive), Self); // No way to avoid the ugly typecast... This is Pascal, after all.. end; 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. Michael. _________________________________________________________________ To unsubscribe: mail with "unsubscribe" as the Subject