I can't make my callback function work. I have created a button which when clicked removes the first button and displays the second button. When I click the button, it removes the first button but does not show the second button. here is the complete code:
File.ads
With Gtk.Widget; Use Gtk.Widget;
With Gtk.Main; Use Gtk.Main;
With Gtk.Window; Use Gtk.Window;
With Gtk.Button; Use Gtk.Button;
With Gtk.Table; Use Gtk.Table;
With Gtk.Handlers; Use Gtk.Handlers;
Package File is
Type T_Test_Record is record
Table : Gtk_Table;
Button_2 : Gtk_Button;
end record;
Type T_Test is access T_Test_Record;
Procedure Init_Button ( Self : access Gtk_Widget_Record'Class; Button : T_Test);
-- Callback for create the second button
Procedure Init_Table ( Table : access T_Test_Record );
-- Initialize the table.
Procedure Exit_Window (Self : access Gtk_Widget_Record'Class);
-- Stop Gtk.Main.Main loop when wen close the window.
Package P is new Gtk.handlers.User_Callback (Gtk_Widget_Record,T_Test);
Use P;
Package P2 is new Gtk.Handlers.Callback (Gtk_Window_Record);
Use P2;
end File;
File.adb
With Gtk.Widget; Use Gtk.Widget;
With Gtk.Table; Use Gtk.Table;
With Gtk.Button; Use Gtk.Button;
Package body File is
Procedure Init_Table (Table : access T_Test_Record ) is
begin
Gtk_New (Table.Table,0,0,False);
end Init_Table;
Procedure Init_Button (Self : access Gtk_Widget_Record'Class;
Button : T_Test) is
begin
Self.Destroy;
Init_Table (Button);
Gtk_New (Button.Button_2);
Button.Button_2.Set_Label ("Bouton 2");
Button.Table.Add (Button.Button_2);
end Init_Button;
Procedure Exit_Window (Self : access Gtk_Widget_Record'Class) is
begin
Gtk.Main.Main_Quit;
end Exit_Window;
end File;
Main.adb
With Gtk.Main; Use Gtk.Main;
With Gtk.Enums; Use Gtk.Enums;
With Gtk.Button; Use Gtk.Button;
With Gtk.Window; Use Gtk.Window;
With Gtk.Grid; Use Gtk.Grid;
With test2; Use Test2;
Procedure Main is
Win : Gtk_Window;
Button : Gtk_Button;
Test : T_Test;
begin
Init;
Test := New T_Test_Record;
Init_Table (Test);
-- Initialize the window
Gtk_New (Win);
Win.Set_Default_Size (600,400);
Win.On_Destroy (test2.Exit_Window'Access);
-- Initialize the Button
Gtk_New (Button,"Bouton 1");
-- Add the Table in the window
Win.Add (Test.Table);
-- Add button in the table
Test.Table.Add (Button);
-- Connect the calllback in the button
Test2.P.Connect (Widget => Button,
Name => Signal_Clicked,
Marsh => Test2.P.To_Marshaller (Init_Button'Access),
User_Data => Test,
After => False);
-- Show the window
Win.Show_All;
Gtk.Main.Main;
end Main;
How can I make my callback function show the second button?