Yeah, Ada doesn't have a good method of preventing overriding of methods.
I made the one version private, but forgot that derived types can still
override them.  I wish Ada had a way to mark procedures as final.

Out of the two options you mentioned, I think #2 is probably better, but
you want to make sure you do a test to see if the input type is of
Window_Type'Class before doing those casts.  You might also consider
casting them to Window_Type'Class rather than just Window_Type in case a
derived type is passed in.

Still I wish I could come up with a better compile time safe method.  I
could make Dialog_Type completely private so View_Type isn't a public
ancestor, but I would need a better method of attaching the views to it,
and it most likely wouldn't follow the Gnoga style.  The other way is for
me to back off the composition and simply make the Modal_Background the
actual Dialog_Type.  Doing that would mean that I need to move some of the
create code into Show and push off the location/size of the view completely
to the implementing client (or also into Show, but with record members that
can save the most recent values of them).  Alternately, I could also take a
look at tabs and cards in Gnoga and see if there are any constructs there
to borrow.

I'll mess around with it more.  What I posted earlier was just stuff I did
for local small projects, so I never spent the needed time to make them a
more general better solution.

On Tue, May 16, 2017 at 12:43 PM, Gautier de Montmollin <gdem...@hotmail.com
> wrote:

> There is a small banana skin with the Create method: when I try to
> extend Gnoga.Gui.View.Modal_Dialog.Dialog_Type for containing its own
> buttons and other elements, like this:
>
>     type Custom_Modal_Type is new
> Gnoga.Gui.View.Modal_Dialog.Dialog_Type with record
>        Hide_Dlg_Bttn  : Gnoga.Gui.Element.Common.Button_Type;
>     end record;
>
> changing the App_Data like this:
>
>     type App_Data (Main_Window : access
> Gnoga.Gui.Window.Window_Type'Class) is
>        new Gnoga.Types.Connection_Data_Type
>     with
>        record
>           Top_Level_View : Gnoga.Gui.View.View_Type;
>           Modal          : Custom_Modal_Type;
>           Show_Dlg_Bttn  : Gnoga.Gui.Element.Common.Button_Type;
>           --  Add other controls here
>        end record;
>
> (and the code around the inner button as following:
>        App.Modal.Hide_Dlg_Bttn.Create (App.Modal, "Hide Dialog");
>        App.Modal.Hide_Dlg_Bttn.On_Click_Handler
> (On_Hide_Dlg_Click'Unrestricted_Access);
> )
>
> then the Create method becomes ambiguous to GNAT (GPL 2016):
>
>        App.Modal.Create (App.Main_Window.all);
>
> modal.adb:69:16: ambiguous call to "Create"
> modal.adb:69:16: possible interpretation (inherited) at line 17
> modal.adb:69:16: possible interpretation (inherited) at line 17
>
> My guess is that it hesitates between the Create in
> Gnoga.Gui.View.Modal_Dialog and the one in Gnoga.Gui.View.
>
> My fix #1 is to rename Create as Create_Modal.
> But I guess you want to prevent people using the Gnoga.Gui.View.Create
> for the modal dialogs.
>
> So my fix #2 is to define this public,
>
>     overriding
>     procedure Create
>        (View             : in out Dialog_Type;
>         Parent           : in out Gnoga.Gui.Base.Base_Type'Class;
>         ID               : in     String := "");
>
> then in the body, convert to Window_Type when needed:
> 11:      Old_View : Gnoga.Gui.Base.Pointer_To_Base_Class :=
> Gnoga.Gui.Window.Window_Type(Parent).Get_View;
> 18: Gnoga.Gui.Window.Window_Type(Parent).Set_View(Old_View.all);
>
> Comments ? Better ideas ?
> Cheers
> Gautier
>
>
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gnoga-list mailing list
> Gnoga-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gnoga-list
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gnoga-list mailing list
Gnoga-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gnoga-list

Reply via email to