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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.157.5.226 with SMTP id 89mr1142207otd.114.1483383057826; Mon, 02 Jan 2017 10:50:57 -0800 (PST) X-Received: by 10.157.37.151 with SMTP id q23mr2340521ota.4.1483383057794; Mon, 02 Jan 2017 10:50:57 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!75no5749849ite.0!news-out.google.com!u18ni6192ita.0!nntp.google.com!75no5749844ite.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 2 Jan 2017 10:50:57 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2001:7e8:dc70:d01:adee:135:2dd1:6efd; posting-account=sDyr7QoAAAA7hiaifqt-gaKY2K7OZ8RQ NNTP-Posting-Host: 2001:7e8:dc70:d01:adee:135:2dd1:6efd References: <29380aa7-0c3b-4908-94c6-aa91f3996b42@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <1c754dc2-01fc-455a-bd9a-01ecb71591af@googlegroups.com> Subject: Re: Experimenting with the OOP features in Ada From: Laurent Injection-Date: Mon, 02 Jan 2017 18:50:57 +0000 Content-Type: text/plain; charset=UTF-8 Xref: news.eternal-september.org comp.lang.ada:33008 Date: 2017-01-02T10:50:57-08:00 List-Id: On Monday, 2 January 2017 17:41:19 UTC+1, Dmitry A. Kazakov wrote: > > You create a new object each time you make assignment. So at the line > 42 > Create_Name creates an object with Name set. Then at the line 45 > Create_Code_SIL overwrites that object with another instance with no > name set. When you try to get its name, the handle of the string is > invalid. An attempt to get the value of gives Constraint_Error. > > P.S. If you want to set components individually you must either expose > > them or else provide setters. > > -- > Regards, > Dmitry A. Kazakov > http://www.dmitry-kazakov.de > Then why didn't it fail immediately on the first run? Antibiotics is a record with 4 of those lazy Safe String objects. Name/=Code_SIL/=CMI/=SIR Each one has its own Create/Value function. Wasn't sure/ had expected (big mistake as always) that I could somehow use the Create/Value functions from Safe String without having to write additional code. The test was actually to figure out how it would work and if it would make a difference compared with the Unbounded_Strings package and with the old version. I am quite tempted in using the persistent storage capabilities of Simple Components but that means that I have to adapt my program to the style of this library. Don't think that it would be possible to only graft it at the latest moment? Now with (Item : in out Something) parameter and adding an "overriding" it works. Not really clear what changed. Perhaps the overriding? BTW what is the reach of the overriding keyword i.e.: overriding function Create_Name (Item : in out Object; Name : String) return Object; function Create_Code_SIL (Item : in out Object; Code_SIL : String) return Object; function Create_CMI (Item : in out Object; CMI : String) return Object; function Create_SIR (Item : in out Object; SIR : String) return Object; function Create (Item : in out Object; Name : String; Code_SIL : String; CMI : String; SIR : String) return Object; private type Object is new Base_Types.Object with record CMI : My_Strings.Handle.My_Safe_String; SIR : My_Strings.Handle.My_Safe_String; end record; end Base_Types.Antibiotics; Gnat was only complaining that Create_Name needs overriding even if Create_Code_SIL is also in the Base_Type which is abstract. Thanks