From: DrPi <314@drpi.fr>
Subject: Re: GtkAda : Trying to derive a widget
Date: Fri, 9 Apr 2021 07:28:46 +0200 [thread overview]
Message-ID: <606fe610$0$3717$426a74cc@news.free.fr> (raw)
In-Reply-To: <s4o00c$sne$1@gioia.aioe.org>
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.
>
> 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.
> 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 ?
>
> This makes the code less fragile if you later decide to choose another
> container widget for the base.
>
Thanks for your help
next prev parent reply other threads:[~2021-04-09 5:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-08 19:27 GtkAda : Trying to derive a widget DrPi
2021-04-08 22:27 ` Dmitry A. Kazakov
2021-04-09 5:28 ` DrPi [this message]
2021-04-09 6:12 ` J-P. Rosen
2021-04-09 11:32 ` DrPi
2021-04-09 6:18 ` Dmitry A. Kazakov
2021-04-09 11:42 ` DrPi
2021-04-09 12:23 ` Dmitry A. Kazakov
2021-04-09 13:37 ` DrPi
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox