[gtkada] Handle signals inside a tagged record

Martin Klaiber martinkl at zedat.fu-berlin.de
Mon Feb 17 16:42:25 CET 2003


Preben Randhol <randhol at pvv.org> wrote:
> Martin Klaiber <martinkl at zedat.fu-berlin.de> wrote on 17/02/2003 (09:53) :

>> I get the error-message:

>>   [...]: no candidate interpretations match the actuals:
>>   [...]: expected type "Handler" defined at gtk-marshallers.ads:335,
>>          instance at gtk-handlers.ads:524, instance at line 32
>>   [...]: found type access to "Update" defined at line 196

>> Handlers is defined as:
>>   package Handlers is 
>>     new Gtk.Handlers.Callback (Widget_Type => Gtk_Widget_Record);

> This is because it expects a Gtk_Widget_Record and not a
> Gtk_Button_Record

Isn't Gtk_Button_Record derived from Gtk_Widget_Record? Anyway, the
problem is not the connection between the button and the signal, as
far as I understand the whole thing. The error is shown in the part
where 'To_Marshaller' is called. See below.

> This should work:

Sorry, but the error-message is exactly the same as above.

>    package Button_Callback is new
>          Gtk.Handlers.Callback (Gtk_Button_Record);

>     Button_Callback.Connect (Ok_Button, "clicked",·
>       Button_Callback.To_Marshaller (Update'Access));
                                             |
The error appears here. ---------------------'

I've read the documentation up and down. Also the signaling-part in
the Gtk-doc. I thought I understood what to do, but everything I try
doesn't work. So probably I misunderstood it.

Most confusing to me is, that in the above error-message:

  [...]: found type access to "Update" defined at line 196

line 196 is the line, where

  Button_Callback.Connect (..., "...", ... (Update'Access));

is called. So does this mean, Update is defined the moment it is used?
And Ada doesn't call the Update-procedure defined in the specification?
I also changed the name to something else to make sure, Ada doesn't mix
it up with some internal function, but the result is the same.

So I tried it like that:

  Button_Callback.Connect (Ok_Button, "clicked",
    Button_Callback.To_Marshaller (Update (Example)'Access));

But this leads to the error-message:

  [...]: prefix of "Access" attribute must be aliased

What does this mean now? When I omit the 'Access, Ada moans that it
expects a type Handler and finds a package or procedure name.

As already mentioned before, the whole thing works, if I have a procedure
like
  
  procedure Button_Ok (Widget : access Gtk_Widget_Record'Class) is
  begin
    anything...
  end Button_Ok;

which doesn't belong to the tagged record Example_Record and call it
with 

  Handlers.Connect (Ok_Button, "clicked", 
    Handlers.To_Marshaller (Button_Ok'Access));

But as I also mentioned, this doesn't help me anything, as it cannot
access any variables within the tagged record.

But what I found out is, that if I change the type called in the
procedure above to something else like Gtk_Button_Record'Class, I
also get the error message:

  [...]: expected type "Handler" defined at gtk-marshallers.ads:335...
  [...]: found type access to "Button_Ok" defined at line 168

The procedure Button_Ok is then also not found by Ada. So, I thought I
might need an additional parameter 'Widget : access...' (see above) in
the specification of Update like that:

  procedure Update (Example : access Example_Record'Class;
    Widget : access Gtk_Widget_Record'Class);

But this doesn't change anything.

Well, I really run out of ideas what to do...

Could it be possible, that it is not possible to call with a signal a
function or procedure which belongs to a tagged record? But then, as
far as I can see, it is done in the example 'base_widget'. But there
the solution seems to be, to define a new type of Marshaller. Is this
the solution?

Thanks for any help,
Martin



More information about the gtkada mailing list