The difference between IF and CASE is, that in the CASE the type of the expression is changed to the type extension. Very handy for message handlers. See below
TYPE
Base = RECORD END
Ext = RECORD (Base) i: INTEGER END;
Ext2 = RECORD (Base) c: CHAR END;
PROCEDURE CaseExample(VAR b: Base);
BEGIN
CASE b OF
Ext: b.i := 0
| Ext2: b.c := „A“
END;
(* this is equivalent *)
IF b IS Ext THEN b(Ext).i := 0
ELSIF b is Ext2 THEN b(Ext2).c := „A“
END
END CaseExample;
Jörg
Andreas wrote:
>
One just needs to get the order right: extended types first, base type last (if one placed the base type at the beginning of the list, it would always evaluate to TRUE even if M were an extension of T)