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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2f63c66b1f04412d X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-17 10:45:17 PST From: "Rodrigo Garcia" Newsgroups: comp.lang.ada References: Subject: Re: How to define an array of a variant record type? Date: Mon, 17 Nov 2003 19:45:00 +0100 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: lglpc31.epfl.ch Message-ID: <3fb91731$1@epflnews.epfl.ch> X-Trace: epflnews.epfl.ch 1069094705 128.178.76.8 (17 Nov 2003 19:45:05 +0200) Organization: EPFL Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!irazu.switch.ch!news-zh.switch.ch!switch.ch!epflnews.epfl.ch!not-for-mail Xref: archiver1.google.com comp.lang.ada:2582 Date: 2003-11-17T19:45:00+01:00 List-Id: "Harald Schmidt" wrote in message news:BBDEBC6C.902D%office@anobject.net... > Hi, > > I would like to define an array, which its element type is a variant record > and the Value_Type is only known at runtime. > > type Name_Value_Type is (String_Type, > Integer_Type, > Float_Type); > > type Name_Value(Value_Type : Name_Value_Type) is > record > The_Name : Unbounded_String; > case Value_Type is > when String_Type => > String_Value : Unbounded_String; > when Integer_Type => > Integer_Value : Integer; > when Float_Type => > The_Value : Float; > end case; > end record; > > type Name_Value_Sequence is array(Natural range <>) of Name_Value; > > The compiler says "unconstrained element type in array declaration", > ...right! > > I know Ada is a strong typed language, but sometimes information is only at > runtime available. Does anyone know some workaround, or a regulare design > pattern for this problem? > > Harald I would use "Indirection": Use an array of _accesses_ to the variant record. type Name_Value_Ptr is access Name_Value; type Name_Value_Sequence is array (Natural range <>) of Name_Value_Ptr; Rodrigo