Path: ...!weretis.net!feeder6.news.weretis.net!feeder8.news.weretis.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Ludovic Brenta Newsgroups: fr.comp.lang.ada Subject: Re: Les Callback en Ada Date: Tue, 21 Sep 2021 19:09:37 +0200 Organization: A noiseless patient Spider Lines: 111 Message-ID: <878rzpx3ce.fsf@samuel> References: <2d7ae0f0-603d-405b-ae05-df8ec6de9cecn@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: reader02.eternal-september.org; posting-host="597fd1af5b5dfb3b12ca05a752557333"; logging-data="24515"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18HP+0wDYTrOL86EwiHJSsk" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Cancel-Lock: sha1:zhnfOG2NqadJRvrpU1U4yUj2L0o= sha1:9f9LNiqU1SX9HSUDDlw5mDpsM7M= Bytes: 4485 Danielle Mandi Mayagha 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=C3=A9dure n'ob=C3=A9it pas au type Gtk.Handlers.User_Callback.Ha= ndler: type Handler is access procedure (Widget : access Widget_Type'Class; -- OK Params : Glib.Values.GValues; -- ignor=C3=A9 User_Data : User_Type); -- pas OK, tu as dit "out P_Fichier.T_Type" =C3=80 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=C3=A9er le dialog= ue comme variable locale dans ta proc=C3=A9dure: 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 =3D> P.On_File_Open'Access); Window.Show_All; Main; end Main; Maintenant, si tu veux r=C3=A9cup=C3=A9rer le nom du fichier et le stocker = dans une variable non locale, je te conseille de faire une extension de type pour ta *fen=C3=AAtre*: 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 :=3D 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 =3D> On_File_Open'Access, Slot =3D> 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; --=20 Ludovic Brenta. The senior support staff transitions our supportive and/or market-based tra= nsformation process round-the-clock.=20