Danielle Mandi Mayagha <
dmandi...@gmail.com> writes:
> package Callback is new gtk.handlers.user_callback (gtk_widget_record, P_fichier.T_Type);
>
> use Callback;
>
> Procedure Stop_Program ( emetteur : access gtk_widget_record;
> object : out P_fichier.T_Type );
>
Cette procédure n'obéit pas au type Gtk.Handlers.User_Callback.Handler:
type Handler is access procedure
(Widget : access Widget_Type'Class; -- OK
Params : Glib.Values.GValues; -- ignoré
User_Data : User_Type); -- pas OK, tu as dit "out P_Fichier.T_Type"
À mon avis tu peux simplifier ton programme. Tu n'as pas besoin d'un
type User_Data. Si tu veux ouvrir un fichier, tu peux créer le dialogue
comme variable locale dans ta procédure:
package body P is
procedure On_File_Open (Button : Gtk.Button.Gtk_Button) is
Dialog : Gtk_File_Chooser_Dialog;
begin
Gtk_New (Dialog);
if Dialog.Run then
-- OK, proceed with the file selected
else
-- user cancelled the dialog
end if;
end On_File_Open;
end P;
procedure Main is
Window : Gtk_Window;
Button : Gtk_Button;
begin
Init;
Gtk_New (Window);
Window.Set_Default_Size (600,400);
Gtk_New (Button, "ouvrir le fichier");
Window.Add (Button);
Button.On_Clicked (Call => P.On_File_Open'Access);
Window.Show_All;
Main;
end Main;
Maintenant, si tu veux récupérer le nom du fichier et le stocker dans
une variable non locale, je te conseille de faire une extension de type
pour ta *fenêtre*:
package Main_Window is
type Record_T is new Gtk.Window.Gtk_Window_Record with private;
type T is access all Record_T'Class;
procedure Gtk_New (Window : out T);
private
type Record_T is new Gtk.Window.Gtk_Window_Record with record
File_Name : Gtk.Label.Gtk_Label;
end record;
end Main_Window;
package body Main_Window is
procedure On_File_Open (Self : access Glib.Object.GObject_Record'Class) is
-- Conformant with Gtk.Button.Cb_GObject_Void
Window : T := T (Self);
Dialog : Gtk_File_Chooser_Dialog;
begin
Gtk_New (Dialog);
if Dialog.Run then
-- OK, proceed with the file selected
Window.Label.Set_Text (Dialog.Get_Filename);
else
-- user cancelled the dialog
Window.Label.Set_Text ("");
end if;
end On_File_Open;
procedure Gtk_New (Window : out T) is
Button : Gtk.Button.Gtk_Button;
begin
Gtk.Window.Gtk_New (Window);
Window.Set_Default_Size (600,400);
Gtk_New (Button, "ouvrir le fichier");
Window.Add (Button);
Button.On_Clicked (Call => On_File_Open'Access, Slot => Window);
-- On_File_Open will receive the specified Window, not the button, as its Self parameter
Gtk_New (Window.Label, "");
Window.Add (Label);
Window.Show_All;
end Gtk_New;
end Main_Window;
procedure Main is
Window : Main_Window.T;
begin
Gtk.Main.Init;
Main_Window.Gtk_New (Window);
Gtk.Main.Main;
end Main;
--
Ludovic Brenta.
The senior support staff transitions our supportive and/or market-based transformation process round-the-clock.