* gtkada3 callback function & failure : subprogram must not be deeper than access type
@ 2019-11-01 18:30 Alain De Vos
2019-11-01 18:47 ` Shark8
2019-11-01 18:57 ` Dmitry A. Kazakov
0 siblings, 2 replies; 3+ messages in thread
From: Alain De Vos @ 2019-11-01 18:30 UTC (permalink / raw)
For callback functions there are 3 methods and one with data.
For the first method I try a program with one button
Connecting the button with the handler fails with the error :
>>>>subprogram must not be deeper than access type
The code :
-- TEST : Connecting via the On_* procedures first method
with Ada.Text_IO; use Ada.Text_IO;
with Glib; use Glib;
with Glib.Object; use Glib.Object;
with Gtk; use Gtk;
with Gtk.Box; use Gtk.Box;
with Gtk.Button; use Gtk.Button;
with Gtk.Enums; use Gtk.Enums;
with Gdk.Event; use Gdk.Event;
with Gtk.Frame; use Gtk.Frame;
with Gtk.Grid; use Gtk.Grid;
with Gtk.Handlers; use Gtk.Handlers;
with Gtk.Label; use Gtk.Label;
with Gtk.Main; use Gtk.Main;
with Gtk.Widget; use Gtk.Widget;
with Gtk.Window; use Gtk.Window;
with Gtk.Main; use Gtk.Main;
procedure hello_gtk is
Main_Window : Gtk.Window.Gtk_Window;
Button : Gtk_Button;
procedure On_Button_Click (Button : access Gtk_Button_Record'Class)
is
begin
Put_line ("Hallo");
end On_Button_Click;
procedure Create_Window is
begin
Gtk.Window.Gtk_New
(Window => Main_Window,
The_Type => Gtk.Enums.Window_Toplevel);
Gtk.Window.Set_Title (Window => Main_Window, Title => "Hello from ADA");
-- Button.On_Clicked (On_Button_Click'Access); fails with subprogram must not be deeper than access type
Add (Main_Window,Button);
Gtk.Window.Show_All (Main_Window);
end Create_Window;
begin
Gtk.Main.Init;
Create_Window;
Gtk.Main.Main;
end hello_gtk;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: gtkada3 callback function & failure : subprogram must not be deeper than access type
2019-11-01 18:30 gtkada3 callback function & failure : subprogram must not be deeper than access type Alain De Vos
@ 2019-11-01 18:47 ` Shark8
2019-11-01 18:57 ` Dmitry A. Kazakov
1 sibling, 0 replies; 3+ messages in thread
From: Shark8 @ 2019-11-01 18:47 UTC (permalink / raw)
Move the On_Button_Click procedure to its own file (on-button-click.ads or something) and add "With On_Button_Click;" to your hello_gtk procedure.
The reason for the error "subprogram must not be deeper than access type" is because the subprogram's access-level is inside the scope of hello_gtk, but the parameter's access-type exceeds that scope: IOW, the access failure is to prevent the dangling-pointer situation where hello_gtk finishes and therefore leaves the scope (thus invalidating the reference to On_Button_Click).
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: gtkada3 callback function & failure : subprogram must not be deeper than access type
2019-11-01 18:30 gtkada3 callback function & failure : subprogram must not be deeper than access type Alain De Vos
2019-11-01 18:47 ` Shark8
@ 2019-11-01 18:57 ` Dmitry A. Kazakov
1 sibling, 0 replies; 3+ messages in thread
From: Dmitry A. Kazakov @ 2019-11-01 18:57 UTC (permalink / raw)
On 2019-11-01 19:30, Alain De Vos wrote:
> For callback functions there are 3 methods and one with data.
> For the first method I try a program with one button
> Connecting the button with the handler fails with the error :
>>>>> subprogram must not be deeper than access type
You can convert the access type. But I will not post how to do this,
because it is bad style and idea.
Move On_Button_Click to a package and it will compile.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-11-01 18:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-01 18:30 gtkada3 callback function & failure : subprogram must not be deeper than access type Alain De Vos
2019-11-01 18:47 ` Shark8
2019-11-01 18:57 ` Dmitry A. Kazakov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox