From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,26a21b9e317dc639 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Received: by 10.224.111.140 with SMTP id s12mr9468606qap.5.1353358337311; Mon, 19 Nov 2012 12:52:17 -0800 (PST) Received: by 10.49.128.233 with SMTP id nr9mr2860154qeb.27.1353358337284; Mon, 19 Nov 2012 12:52:17 -0800 (PST) Path: gf5ni327qab.0!nntp.google.com!u2no13641830qal.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 19 Nov 2012 12:52:17 -0800 (PST) In-Reply-To: <9b0bcb37-8ae3-440f-af4f-a796702e4250@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=85.227.237.85; posting-account=l8k8IwoAAADeDydswOzwNzmn10qOk9gt NNTP-Posting-Host: 85.227.237.85 References: <9b0bcb37-8ae3-440f-af4f-a796702e4250@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <6e3f6f2d-d221-4795-9c01-9abb013442b7@googlegroups.com> Subject: Re: Access type to member procedure of instance (Object Oriented programming in Ada) From: ake.ragnar.dahlgren@gmail.com Injection-Date: Mon, 19 Nov 2012 20:52:17 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-11-19T12:52:17-08:00 List-Id: On Monday, November 19, 2012 10:59:42 AM UTC+1, ake.ragna...@gmail.com wrot= e: > Not sure if this has already been discussed but: Is it possible to define= a pointer to a member procedure of an instance? >=20 >=20 >=20 > This problem has it's origin in the implementation of the MVC pattern for= a GtkAda application. Consider the following: >=20 >=20 >=20 > package Some_Package is >=20 >=20 >=20 > type Message_Type is tagged null record; >=20 > =20 >=20 > procedure Print(Message : Message_Type); >=20 >=20 >=20 > end Some_Package; >=20 >=20 >=20 >=20 >=20 >=20 >=20 > package body Some_Package is >=20 >=20 >=20 > procedure Print (Message : Message_Type) is >=20 > begin >=20 > null; >=20 > end Print; >=20 >=20 >=20 > end Some_Package; >=20 >=20 >=20 >=20 >=20 > Then it is possible to create the following Main application that compile= s just fine: >=20 >=20 >=20 > with Some_Package; >=20 >=20 >=20 > procedure Main is >=20 > Message : Some_Package.Message_Type; >=20 > begin >=20 > Message.Print; >=20 > end Main; >=20 >=20 >=20 > Is it possible to create a parameterless access type to the Message.Print= procedure? The following application refuses to compile: >=20 >=20 >=20 > with Some_Package; >=20 >=20 >=20 > procedure Main is >=20 > Message : Some_Package.Message_Type; >=20 > =20 >=20 > Method_Ref : access procedure :=3D Message.Print'Access; >=20 > begin >=20 > Method_Ref; >=20 > end Main; >=20 >=20 >=20 > The error message is: no selector "Print" for type "Message_Type" defined= at some_package.ads:3 >=20 >=20 >=20 >=20 >=20 > It is possible to create a workaround: >=20 >=20 >=20 > with Some_Package; >=20 >=20 >=20 > procedure Main is >=20 > Message : Some_Package.Message_Type; >=20 > =20 >=20 > procedure Method_Ref is >=20 > begin >=20 > Message.Print; >=20 > end Method_Ref; >=20 > =20 >=20 > begin >=20 > Method_Ref; >=20 > end Main; >=20 >=20 >=20 > Is there a better way? Or is this the optimal way? >=20 >=20 >=20 > Regards, >=20 > =C5ke Ragnar Dahlgren Actually I've been thinking. The workaround worked for the contrived exampl= e above but not for my Gtkada application. What inspired the Gtkada application I've been experimenting with is the ex= planation given by Ada in Denmark on their wiki: http://wiki.ada-dk.org/building_gui_with_glade_3 What one can see there is that a Builder instance is created and when the a= pplication quits it is deallocated. This makes the code suitable for using = Ada's object oriented features and to let the Builder instance be created i= n the Initialize procedure and let it be deallocated in the Finalize proced= ure. Also it is possible to see that the callbacks are declared in the Simple_Ca= llbacks package. Note that the methods are not instance member methods. I hope I am wrong but it seems to me that since Ada lacks the ability to cr= eate pointers (maybe access types are the right words) to instance member m= ethods, it is not possible to take advantage of Ada's OOP features when dev= eloping Glade3 applications. Best regards, =C5ke Ragnar Dahlgren