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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,769e61538eb61436 X-Google-Attributes: gid103376,public From: jsa@organon.com (Jon S Anthony) Subject: Re: Variant record assignment Q: Date: 1996/07/10 Message-ID: #1/1 X-Deja-AN: 167629571 sender: news@organon.com (news) references: <31E32A82.3984D09E@jinx.sckans.edu> organization: Organon Motives, Inc. newsgroups: comp.lang.ada Date: 1996-07-10T00:00:00+00:00 List-Id: In article <31E32A82.3984D09E@jinx.sckans.edu> David Morton writes: > I would like to be able to say, > > Tmp : String_Ptr; > Root : Object_Ptr; > > Tmp := new String("test"); ^needs a "'" as in String'("test") > Root := new Object(Button)'(Status => Button, X => 10, Y => 10, Name => Tmp, Status => > Something); The discriminant is just part of the aggregate: Root := new Object'(Obj => Button, ....); > One particular error I tend to get (that is confusing me)is: > > > Tmp := new String'("test"); > > Root := new Object(Obj => Button); -- line 24 BTW > Root.all := (Status => Button, X => 10,Y => 10, Name => Tmp, Status_Code => This); > > user_info_management.adb:25:13: no value supplied for discriminant "Obj" There are two problems here. First, you can't make an assignment to a discriminated record without specifying the discriminant. So, you would need to say: Root.all := (Obj => Button, ...); Second, you can't change the discriminant of a constrained object which is what Root.all is as the discriminant in its type has no default. So, you can't do the Root.all assignment anyway. You have several options. * You can assign individual fields (probably not what you really want) * You can give the full value when you create the (constrained) object: Root := new Object'(...disriminant and all the other fields...). * You can change the type so that it has defaults for the discriminants and then do the full assignment mentioned above. Depending on what you really are trying to accomplish there are probably others (for example using tagged types instead of discriminated record) /Jon -- Jon Anthony Organon Motives, Inc. 1 Williston Road, Suite 4 Belmont, MA 02178 617.484.3383 jsa@organon.com