From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!news.mixmin.net!proxad.net!feeder1-2.proxad.net!212.27.60.64.MISMATCH!cleanfeed3-b.proxad.net!nnrp1-2.free.fr!not-for-mail Newsgroups: comp.lang.ada References: <606f5938$0$27421$426a74cc@news.free.fr> <606fe610$0$3717$426a74cc@news.free.fr> From: DrPi <314@drpi.fr> Subject: Re: GtkAda : Trying to derive a widget Date: Fri, 9 Apr 2021 13:42:02 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Message-ID: <60703d8c$0$6192$426a74cc@news.free.fr> Organization: Guest of ProXad - France NNTP-Posting-Date: 09 Apr 2021 13:42:04 CEST NNTP-Posting-Host: 82.65.30.55 X-Trace: 1617968524 news-1.free.fr 6192 82.65.30.55:52838 X-Complaints-To: abuse@proxad.net Xref: reader02.eternal-september.org comp.lang.ada:61766 List-Id: Le 09/04/2021 à 08:18, Dmitry A. Kazakov a écrit : > On 2021-04-09 07:28, DrPi wrote: >> Le 09/04/2021 à 00:27, Dmitry A. Kazakov a écrit : >>> On 2021-04-08 21:27, DrPi wrote: >>> >>>> I'm trying to create a GtkAda widget derived from a standard widget. >>>> >>>> -- debug_panel.ads >>>> with Gtk.Scrolled_Window; use Gtk.Scrolled_Window; >>>> with Gtk.Text_View;       use Gtk.Text_View; >>>> >>>> package Debug_Panel is >>>> >>>>    type Debug_Panel_Record is new Gtk_Scrolled_Window_Record with >>>> private; >>>>    type Debug_Panel is access all Debug_Panel_Record'Class; >>>> >>>> >>>>    procedure Gtk_New (Panel : in out Debug_Panel); >>>>    procedure Initialize (Panel : not null access >>>> Debug_Panel_Record'Class); >>>> >>>> private >>>> >>>>    type Debug_Panel_Record is new Gtk_Scrolled_Window_Record with >>>> record >>>>       Text       : Gtk_Text_View; >>>>    end record; >>>> >>>> end Debug_Panel; >>>> >>>> >>>> -- debug_panel.adb >>>> package body Debug_Panel is >>>> >>>>    procedure Gtk_New (Panel : in out Debug_Panel) is >>>>    begin >>>>       Panel := new Debug_Panel_Record; >>>>       Initialize (Panel); >>> >>>    Debug_Panel.Initialize (Panel); >> I did try this notation and got this error : >> debug_panel.adb:6:07: invalid prefix in selected component "Debug_Panel" >> debug_panel.adb:6:18: prefixed call is only allowed for objects of a >> tagged type >> >> I've just realized this is because the package and the access type >> have the same name. > > You can disambiguate it so: > >   Standard.Debug_Panel.Initialize (Panel) > >   Standard.Debug_Panel - The package name >   Standard.Debug_Panel.Debug_Panel - The type name > Ah. I have to remember this. That makes "Standard" some sort of reserved keyword. >>> Another way would be to remove "use Gtk.Scrolled_Window" and declare as >>> >>>    type Debug_Panel_Record is >>>       new Gtk.Scrolled_Window.Gtk_Scrolled_Window_Record with private; >>> >>> Without "use" Initialize is unambiguous. >>> >> That makes sense. >> However, I don't understand why there is ambiguity when using "use". >> Debug_Panel (the type) is of type Debug_Panel_Record, so Initialize >> should resolve to the one using this type. Well, I guess I'm wrong. > > Debug_Panel belongs to both Debug_Panel_Record'Class and > Gtk_Scrolled_Window_Record'Class (and many other classes), so the > ambiguity. > Surprising behaviour for a strongly typed language but there surely is a good reason. >>> P.S. When you create new widget it is better to use a more general >>> ancestor hiding insufficient details, e.g. >>> >>>    type Debug_Panel_Record is >>>       new Gtk.Widget.Gtk_Widget_Record with private; >>>    ... >>> private >>>    type Debug_Panel_Record is >>>       new Gtk.Scrolled_Window.Gtk_Scrolled_Window_Record with >>>    record >>>       ... >>>    end record; >> >> I'm surprized this is possible to write such a thing in Ada. >> What does the compiler do with this ? > > The public view is Gtk_Widget_Record [with no record members], the full > view is Gtk_Scrolled_Window_Record [with record members you specified]. > Ok.