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,LOTS_OF_MONEY autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,13703514e3723cbe X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-14 00:37:52 PST From: "Martin Dowie" Newsgroups: comp.lang.ada References: <9l7qon$d78$1@nntp9.atl.mindspring.net> <7E0e7.12187$vW2.6599957@news1.sttln1.wa.home.com> <9la73h$vvs$1@slb6.atl.mindspring.net> Subject: Re: C-style 'union' in Ada? Date: Tue, 14 Aug 2001 08:37:44 +0100 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 NNTP-Posting-Host: sg2c11210.dsge.edinbr.gmav.gecm.com Message-ID: <3b78d2d4$1@pull.gecm.com> X-Trace: 14 Aug 2001 08:27:16 GMT, sg2c11210.dsge.edinbr.gmav.gecm.com Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!btnet-peer1!btnet-peer0!btnet-feed5!btnet!newreader.ukcore.bt.net!pull.gecm.com!sg2c11210.dsge.edinbr.gmav.gecm.com Xref: archiver1.google.com comp.lang.ada:11894 Date: 2001-08-14T08:37:44+01:00 List-Id: The trick (if you could call it that!) is to include a default value for the discriminant in the type definition. You can then change its value at will. If you don't have a default then you have to contraint the object when you declare it - which then fixes it to that value. Brian Catlin wrote in message news:9la73h$vvs$1@slb6.atl.mindspring.net... > I didn't know that a discriminant could be assigned at run time. This is close to what I want to do. > > Thanks! > -Brian > > "DuckE" wrote in message news:7E0e7.12187$vW2.6599957@news1.sttln1.wa.home.com... [snip] > > procedure string_demo is > > > > type str_type is ( ansi, wide ); > > > > type string_desc( str_select : str_type := ansi ) is > > record > > case str_select is > > when ansi => > > ansi_string : String_Access; > > when wide => > > wide_string : Wide_String_Access; > > end case; > > end record; > > > > begin > > declare > > str : string_desc; > > begin > > str := ( str_select => ansi, ansi_string => new String'( "Hello" ) ); > > Free( str.ansi_string ); > > str := ( str_select => wide, wide_string => new Wide_String'( > > "There" ) ); > > Free( str.wide_string ); > > end; > > end string_demo; >