The Storage variable is uninitialised. Therefore for each entry the same variant (the default Desk) is stored and the discriminant check fails.

Now initialisation is apt to get very tedious as we shall see presently if not done in a smart way. First we add a component denoting whether there is stored anything at all.

The package body gets an executable part (executed during elaboration):

To our dismay, with this method in a way we have to repeat the whole record declaration. If we have many variants, this is getting really awkward.

Fortunately all this is unnecessary if we add the correct default values to the record declaration:

Initialising now is really simple.

Note the variable declaration without an initial value - a constant would need an initial value and we would be back at the problem how to denote it. (By the way: Declarations without initial value are strictly disallowed by some coding standards, especially when the variable is never assigned a value, as is the case here! But as we have seen, sometimes seemingly obvious nonsense is unavoidable and - if done in the correct way - perfectly legal.)

Contents        © Copyright 1998 C.K.W. Grein