comp.lang.ada
 help / color / mirror / Atom feed
* Variant record assignment Q:
@ 1996-07-09  0:00 David Morton
  1996-07-10  0:00 ` David Morton
  1996-07-10  0:00 ` Jon S Anthony
  0 siblings, 2 replies; 4+ messages in thread
From: David Morton @ 1996-07-09  0:00 UTC (permalink / raw)



hello again...
given the specification:

   type String_Ptr is access all string;
   type Object_Type is (Field, Button);
   type Object;
   type Object_Ptr is access Object;
   type Object(Obj : Object_Type) is
      record
     Status : Object_Type;
	 Next, Prev : Object_Ptr;
	 case Obj is
	    when Field =>
	       Label_X, Label_Y, Field_X, Field_Y, Buffer_Size, Max_Buffer_Size : natural;
	       Buffer : String_Ptr;
	       Field_Name : String_Ptr;
	    when Button =>
	       X, Y : natural;
	       Name : String_Ptr;
	       Status_Code : Return_Code;
	 end case;
      end record;

What's the quickest way to instantiate this?
I would like to be able to say,

Tmp : String_Ptr;
Root : Object_Ptr; 

Tmp := new String("test");
Root := new Object(Button)'(Status => Button, X => 10, Y => 10, Name => Tmp, Status =>
Something);

but I get errors, both with the string and record instantiations.
I've tried several variations, but no better...

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"

Thanks for any help!

(I'll figure this stuff out yet!)
-- 
David Morton
 mailto:dmorton@jinx.sckans.edu   http://www.sckans.edu/~dmorton/
 205 College, Winfield, KS 67156    
 This signature will self-destruct in 10 seconds...




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Variant record assignment Q:
  1996-07-09  0:00 Variant record assignment Q: David Morton
@ 1996-07-10  0:00 ` David Morton
  1996-07-11  0:00   ` Steve O'Neill
  1996-07-10  0:00 ` Jon S Anthony
  1 sibling, 1 reply; 4+ messages in thread
From: David Morton @ 1996-07-10  0:00 UTC (permalink / raw)



David Morton wrote:
> 
> hello again...
> given the specification:
> 
>    type String_Ptr is access all string;
>    type Object_Type is (Field, Button);
>    type Object;
>    type Object_Ptr is access Object;
>    type Object(Obj : Object_Type) is
>       record
>      Status : Object_Type;
>          Next, Prev : Object_Ptr;
>          case Obj is
>             when Field =>
>                Label_X, Label_Y, Field_X, Field_Y, Buffer_Size, Max_Buffer_Size : natural;
>                Buffer : String_Ptr;
>                Field_Name : String_Ptr;
>             when Button =>
>                X, Y : natural;
>                Name : String_Ptr;
>                Status_Code : Return_Code;
>          end case;
>       end record;
> 
> What's the quickest way to instantiate this?
> I would like to be able to say,
> 
> Tmp : String_Ptr;
> Root : Object_Ptr;
> 
> Tmp := new String("test");
> Root := new Object(Button)'(Status => Button, X => 10, Y => 10, Name => Tmp, Status =>
> Something);
> 
> but I get errors, both with the string and record instantiations.
> I've tried several variations, but no better...
> 
> 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"
> 
> Thanks for any help!
> 
> (I'll figure this stuff out yet!)

whoops...  forgot to mention Ada95 here... gnat on Linux...

-- 
David Morton
 mailto:dmorton@jinx.sckans.edu   http://www.sckans.edu/~dmorton/
 205 College, Winfield, KS 67156    
 This signature will self-destruct in 10 seconds...




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Variant record assignment Q:
  1996-07-09  0:00 Variant record assignment Q: David Morton
  1996-07-10  0:00 ` David Morton
@ 1996-07-10  0:00 ` Jon S Anthony
  1 sibling, 0 replies; 4+ messages in thread
From: Jon S Anthony @ 1996-07-10  0:00 UTC (permalink / raw)



In article <31E32A82.3984D09E@jinx.sckans.edu> David Morton <dmorton@jinx.sckans.edu> 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





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Variant record assignment Q:
  1996-07-10  0:00 ` David Morton
@ 1996-07-11  0:00   ` Steve O'Neill
  0 siblings, 0 replies; 4+ messages in thread
From: Steve O'Neill @ 1996-07-11  0:00 UTC (permalink / raw)



David Morton wrote:
> given the specification:
>
> type String_Ptr is access all string;
> type Object_Type is (Field, Button);
> type Object;
> type Object_Ptr is access Object;
> type Object(Obj : Object_Type) is record
>   Status : Object_Type;
>   Next, Prev : Object_Ptr;
>   case Obj is
>     when Field =>
>       Label_X, Label_Y, 
>       Field_X, Field_Y, 
>       Buffer_Size, x_Buffer_Size : natural;
>       Buffer : String_Ptr;
>       Field_Name : String_Ptr;
>     when Button =>
>       X, Y : natural;
>       Name : String_Ptr;
>       Status_Code : Return_Code;
>   end case;
> end record;
>
> One particular error I tend to get (that is confusing me)is:
>
> 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"

That's because Obj (the discriminant) is also part of the record and
must be assigned a value.  So the assignment would be:
  Root.all := (Obj => Button,
               Status => Button, 
               Next => Something,
               Previous => Something,
               X => 10,Y => 10, 
               Name => Tmp, 
               Status_Code => This);

Assuming valid values for Something, Tmp and This, of course.  Perhaps
this is what you had in mind by having the Status component.

-- 
Steve O'Neill                      | "No,no,no, don't tug on that!
Sanders, A Lockheed Martin Company |  You never know what it might
smoneill@sanders.lockheed.com      |  be attached to." 
(603) 885-8774  fax: (603) 885-4071|    Buckaroo Banzai




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1996-07-11  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-07-09  0:00 Variant record assignment Q: David Morton
1996-07-10  0:00 ` David Morton
1996-07-11  0:00   ` Steve O'Neill
1996-07-10  0:00 ` Jon S Anthony

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