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-Received: by 2002:a5d:854f:: with SMTP id b15mr6823397ios.36.1545506021368; Sat, 22 Dec 2018 11:13:41 -0800 (PST) X-Received: by 2002:a9d:2c22:: with SMTP id f31mr143478otb.4.1545506021291; Sat, 22 Dec 2018 11:13:41 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!feeder4.usenet.farm!feed.usenet.farm!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!q69no186664itb.0!news-out.google.com!v141ni248ita.0!nntp.google.com!k10no186717itk.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 22 Dec 2018 11:13:40 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=50.66.161.135; posting-account=lzqe5AoAAADHhp_gregSufVhvwu22fBS NNTP-Posting-Host: 50.66.161.135 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <6fa96f1a-c7d3-491a-a822-754bac6d50e7@googlegroups.com> Subject: =?UTF-8?Q?Re=3A_=D0=A1reate_attributes=2E?= From: Brad Moore Injection-Date: Sat, 22 Dec 2018 19:13:41 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:55105 Date: 2018-12-22T11:13:40-08:00 List-Id: On Friday, December 21, 2018 at 10:37:14 PM UTC-7, eduards...@gmail.com wrote: > Sorry for the stupid question... > > For example. I have type: > > type Person is record > First_Name : Unbounded_String := Null_Unbounded_String; > Last_Name : Unbounded_String := Null_Unbounded_String; > end record; > > There is a list: > > package People_Package is new Ada.Containers.Vectors(Natural, Person); > People : People_Package.Vector; > > Next, I want to display this list with headers: > > ---------------------------- > | NAME | SURNAME | > ---------------------------- > | John | Smith | > | Ada | Lovelace | > ... > ---------------------------- > > Can I use attributes to display headers? > For example something like this: > > People'First_Name_Header > > > How can this be implemented? You could use a class-wide type or a type with discriminants such as; type Person_Attribute_Kinds is (Name, Surname); type Person_Attribute (Attribute_Name : Person_Attribute_Kinds := Person_Attribute_Kinds'First) is record case Attribute_Name is when Name | Surname => Name_String : Unbounded_String := Null_Unbounded_String; end case; end record; type Person is record First_Name : Person_Attribute(Name); Last_Name : Person_Attribute(Surname); end record; X : Person; begin Put_Line ("| " & X.First_Name.Attribute_Name'Image & " | " & X.Last_Name.Attribute_Name'Image & " |");