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=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Experimenting with the OOP features in Ada Date: Tue, 3 Jan 2017 15:31:13 +0100 Organization: Aioe.org NNTP Server Message-ID: References: <29380aa7-0c3b-4908-94c6-aa91f3996b42@googlegroups.com> NNTP-Posting-Host: s3c6wwRqkurrfTZpuYYZ+w.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:33021 Date: 2017-01-03T15:31:13+01:00 List-Id: On 2017-01-03 14:57, Laurent wrote: > The only thing which I am not able to see is if I can transform this into a > procedure and how I would do it. The Ptr confuses me because I don't > understand where it should point to in a procedure. > > function Create (Value : String) return My_Safe_String > is > Ptr : My_String_Ptr := new My_String (Value'Length); > begin > Ptr.Value := Value; > return Ref (Ptr); > end Create; In the sample code this procedure is called Copy. Regarding using in-place notation that would be: Value.Set (new My_String'(Object.Entity with Value'Length, Value)); > Item.Name.Set (Name=>"Something") looks better than > > Item.Name := My_Strings.Handle.Create (Value => Name); Some people like using unary "+" for this. E.g. function "+" (Value : String) return My_Safe_String renames My_Strings.Handle.Create; Then you can do: Item.Name := +"Something"; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de