comp.lang.ada
 help / color / mirror / Atom feed
From: anon@anon.org (anon)
Subject: Re: Using discriminant record: problem with assigning to an array in body
Date: Tue, 17 Mar 2009 20:24:42 GMT
Date: 2009-03-17T20:24:42+00:00	[thread overview]
Message-ID: <eGTvl.65622$4m1.63840@bgtnsc05-news.ops.worldnet.att.net> (raw)
In-Reply-To: 976bd0a5-4aff-4f40-83c7-c6b7829ab4d8@s9g2000prg.googlegroups.com

-- try this one:
--
procedure test is

type GOODS_TYPE is ( LIQUID, TEXTILE);

-- Ada prefers array to be predefined for usage in records 
type float_array is array ( 0..5 ) of float;

type TYPE_GOODS( GOODS_TYPE_SELECTION : GOODS_TYPE) is
  record

    case GOODS_TYPE_SELECTION is
       when LIQUID =>
           ITEM_NAME : float_array ; -- new type defined and stops compiler errors

       when TEXTILE =>
           LENGTH : float;
           WIDTH : float;
    end case;
  end record;

  A : TYPE_GOODS( LIQUID );

  begin

  A := ( GOODS_TYPE_SELECTION => LIQUID,
            ITEM_NAME => (1.0, 1.1, 1.2, 1.3, 1.4,1.5) );

end test;



In <976bd0a5-4aff-4f40-83c7-c6b7829ab4d8@s9g2000prg.googlegroups.com>, ChristopherL <clusardi2k@aol.com> writes:
>The below procedure compiles and links fine, but when I run it I get a
>"discriminant check failed" error message. Can you please modify this
>code so that the array assignment works.
>
>procedure test is
>
>type GOODS_TYPE is ( LIQUID, TEXTILE);
>
>type TYPE_GOODS( GOODS_TYPE_SELECTION : GOODS_TYPE) is
>  record
>
>    case GOODS_TYPE_SELECTION is
>       when LIQUID =>
>           ITEM_NAME : is array ( 0..5 ) of float;
>
>       when TEXTILE =>
>           LENGTH : float;
>           WIDTH : float;
>    end case;
>  end record;
>
>  A : TYPE_GOODS( LIQUID );
>
>  begin
>
>  A := ( GOODS_TYPE_SELECTION => LIQUID,
>            ITEM_NAME => (1.0, 1.1, 1.2, 1.3, 1.4,1.5) );
>
>end test;




  parent reply	other threads:[~2009-03-17 20:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <976bd0a5-4aff-4f40-83c7-c6b7829ab4d8@s9g2000prg.googlegroups.com>
2009-03-17 20:05 ` Using discriminant record: problem with assigning to an array in body of case (see below)
2009-03-17 20:24 ` anon [this message]
2009-03-17 20:50 ` Jeffrey R. Carter
2009-03-17 21:15 ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox