comp.lang.ada
 help / color / mirror / Atom feed
From: dennison@telepath.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: <7fks8u$8k1$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:
> Robert Dewar 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?

Whenever you change the discriminant of a variant record, you also have to
change *all* the other fields (in the same assignment). That prevents you
from getting "new" fields in your record with garbage values in them.

This also prevents you from hosing the type of one of the fields by changing
the variant so that its type changes out from under it.

--
T.E.D.

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




  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     ` Pawel Kobylarz
1999-04-21  0:00       ` dennison [this message]
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
1999-04-21  0:00     ` bglbv
1999-04-22  0:00       ` dennison
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