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.219.144 with SMTP id hu16mr517369qab.1.1353577660942; Thu, 22 Nov 2012 01:47:40 -0800 (PST) Received: by 10.49.116.139 with SMTP id jw11mr673qeb.12.1353577659919; Thu, 22 Nov 2012 01:47:39 -0800 (PST) Path: gf5ni2982588qab.0!nntp.google.com!i9no8424261qap.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 22 Nov 2012 01:47:39 -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=136.163.203.8; posting-account=l8k8IwoAAADeDydswOzwNzmn10qOk9gt NNTP-Posting-Host: 136.163.203.8 References: <9b0bcb37-8ae3-440f-af4f-a796702e4250@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Access type to member procedure of instance (Object Oriented programming in Ada) From: ake.ragnar.dahlgren@gmail.com Injection-Date: Thu, 22 Nov 2012 09:47:40 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-11-22T01:47:39-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? This problem has it's orig= in in the implementation of the MVC pattern for a GtkAda application. Consi= der the following: package Some_Package is type Message_Type is tagged null= record; procedure Print(Message : Message_Type); end Some_Package; package= body Some_Package is procedure Print (Message : Message_Type) is begin nul= l; end Print; end Some_Package; Then it is possible to create the following= Main application that compiles just fine: with Some_Package; procedure Mai= n is Message : Some_Package.Message_Type; begin Message.Print; end Main; Is= it possible to create a parameterless access type to the Message.Print pro= cedure? The following application refuses to compile: with Some_Package; pr= ocedure Main is Message : Some_Package.Message_Type; Method_Ref : access pr= ocedure :=3D Message.Print'Access; begin Method_Ref; end Main; The error me= ssage is: no selector "Print" for type "Message_Type" defined at some_packa= ge.ads:3 It is possible to create a workaround: with Some_Package; procedur= e Main is Message : Some_Package.Message_Type; procedure Method_Ref is begi= n Message.Print; end Method_Ref; begin Method_Ref; end Main; Is there a bet= ter way? Or is this the optimal way? Regards, =C5ke Ragnar Dahlgren I want to thank everybody for replying. I had no idea about the "renames" f= eature as Randy pointed out. Brian expressed it very well: I am astonished! As for the Gtkada application I have given up on implementing the MVC patte= rn using tagged types. Instead I choose the same approach as was done in th= e Ada in Denmark wiki. Best regards, =C5ke Ragnar Dahlgren