Figure 28.
You can't change the constraint alone.
------------------------------------------------------------
-- This procedure illustrates the consequences of LRM
-- Section 3.7.1 paragraph 9.
procedure Cant_Change_Constraint_Alone is
type Default (LENGTH : natural := 0) is
record
TEXT : string(1..LENGTH);
end record;
WHOLE_NAME : Default(14);
LAST_NAME : Default;
begin
-- I can let LAST_NAME hold a 5 character name.
LAST_NAME := (LENGTH => 5, TEXT => "Jones");
-- Then I can change those five characters alone.
LAST_NAME.TEXT := "Smith";
-- But I can't change the discriminant alone.
LAST_NAME.LENGTH := 10; -- ILLEGAL
-- WHOLE_NAME was constrained to be 14 characters,
-- so I can do this:
WHOLE_NAME.TEXT := "Do-While Jones";
-- And I can expand LAST_NAME by changing both the
-- LENGTH and TEXT in one shot by an assignment
-- statement.
LAST_NAME := WHOLE_NAME;
-- (LAST_NAME now contains (14,"Do-While Jones").)
-- Or I can assign the whole record using an
-- aggregate, like this:
LAST_NAME := (5, "Jones");
end Cant_Change_Constraint_Alone;