[gtkada] Question wrt using the new paradigm for connecting handlers to signals

Emmanuel Briot briot at adacore.com
Mon Oct 26 10:29:11 CET 2015


> Is there a way to use the new paradigm without the conversion to/from a Gtype_Interface ?

Not really.
These new On_* subprograms are really simple wrappers around the old way, so mixing both
in your application will definitely work, and there are no drawback.
When they are generated, the type used for "Self" is that of the widget or interface that
declares the signal. So if you are using a child type, you will have to convert the types in
your callback. In practice, this conversion is safe (since otherwise you cannot call On_* in
the first place), and well worth adding in exchange for some more static type checking that
the compiler can do with the new approach (for the parameters other than Self).

> procedure Handler (Object : access gtk_combo_box_text_record’class);
> type Cb_GObject_Void is not null access procedure (Self : access Glib.Object.GObject_Record'Class);
> 
> I would have expected that the compiler complains about actual type of “Handler” not being (subtype) compatible / conformant to the formal type Cb_Gtk_Combo_Box_Void

There is no notion of subtype compatibility here. The exact profile must be the same in Ada,
so your Handler indeed needs to accept an access to GObject_Record'Class, and do a type
conversion internally, as explained above.

> I can’t find an obvious way to do a type conversion without running into accessibility level violations, and I guess that the type conversion isn’t even allowed.

Accessibility level violations are unrelated to the errors you are seeing with the
improper matching of types. You likely declare the Handler as a nested subprogram
in your main procedure, I would guess. That's not the way real applications are structured
in practice (the callbacks are always defined at library level in other packages), but for small
demos you should use Handler'Unrestricted_Access rather than Handler'Access.

regards
Emmanuel



More information about the gtkada mailing list