From: Brad Moore <bmoore.ada@gmail.com>
Subject: Re: Сreate attributes.
Date: Sat, 22 Dec 2018 11:13:40 -0800 (PST)
Date: 2018-12-22T11:13:40-08:00 [thread overview]
Message-ID: <6fa96f1a-c7d3-491a-a822-754bac6d50e7@googlegroups.com> (raw)
In-Reply-To: <f38540f4-d18c-4eac-bb79-de126b655583@googlegroups.com>
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 & " |");
next prev parent reply other threads:[~2018-12-22 19:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-22 5:37 Сreate attributes eduardsapotski
2018-12-22 19:13 ` Brad Moore [this message]
2018-12-28 9:26 ` eduardsapotski
2019-01-01 18:47 ` Brad Moore
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox