comp.lang.ada
 help / color / mirror / Atom feed
From: czgrr <czgrr@my-dejanews.com>
Subject: Re: Can I have an array of variant records?
Date: 1999/04/21
Date: 1999-04-21T00:00:00+00:00	[thread overview]
Message-ID: <7fkruq$878$1@nnrp1.dejanews.com> (raw)
In-Reply-To: 371DC9BE.585254A6@wbkst21.mach.uni-karlsruhe.de

In article <371DC9BE.585254A6@wbkst21.mach.uni-karlsruhe.de>,
  kobylarz@wbkst21.mach.uni-karlsruhe.de wrote:
> How to alter the discriminant? I searched in several different sources of
> documentation
> and I have not found that.
>
> I declared variant record:
>
> type Tool_Operation(action : Action_Type := Wait) is
>   record
>     case action is
>       when Wait => howlong : time;
>       when Move => where : position; min_time : time;
>     end case;
>   end record;
>
> Let's define variable:
>
>    top : Tool_Operation;
>
> But such statement does not compile:
>
>         top.action := Move;
>
> The compiler returns error: "left hand side of assignment must be a
> variable"
>
> How to alter the discriminant?

The discriminant can not be assigned directly, like the other fields in the
record. In order to assign it, you must also assign every other field in that
variant at the same time, otherwise they would be undefined. Hence, you have
to do something like this...

top :=
  ( action   => Move,
    where    => ...,     -- these are part of
    min_time => ... ) ;  -- the "Move" variant

Changing the discriminant back to "Wait" is a similar process. BTW, that means
that you lose the previous value of "howlong".

czgrr

--
My opinions, suggestions, etc, are not necessarily those of my employer.
They might not even be right. Use at your own risk.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




  parent reply	other threads:[~1999-04-21  0:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-04-20  0:00 Can I have an array of variant records? Josh Highley
1999-04-20  0:00 ` bglbv
1999-04-21  0:00   ` Robert Dewar
1999-04-21  0:00     ` bglbv
1999-04-22  0:00       ` dennison
1999-04-21  0:00     ` Pawel Kobylarz
1999-04-21  0:00       ` dennison
1999-04-21  0:00         ` Robert Dewar
1999-04-22  0:00           ` Josh Highley
1999-04-23  0:00           ` Pawel Kobylarz
1999-04-21  0:00       ` David C. Hoos, Sr.
1999-04-21  0:00         ` Robert Dewar
1999-04-21  0:00       ` czgrr [this message]
1999-04-21  0:00 ` Robert Dewar
1999-04-22  0:00 ` Maybe not exactly a variant record Josh Highley
1999-04-22  0:00   ` dennison
1999-04-23  0:00     ` Nick Roberts
replies disabled

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