[fpc-pascal] Case in Record
Jürgen Hestermann
juergen.hestermann at gmx.de
Wed Oct 7 07:22:58 CEST 2009
> AFAIK there has to be some fixed part before the variant, e. g.
> TFigure = record
> name: string;
> case TShapeList of
> Rectangle: (Height, Width: Real);
> Triangle: (Side1, Side2, Angle: Real);
> Circle: (Radius: Real);
> Ellipse, Other: ();
> end;
> The program could then determine from the contents of the "name" field
> which variant is used in a certain instance.
How would that work? "name" is just a string which you can assign an
arbitrary value to. The compiler cannot store additional information in it.
The detection of the correct variant is completely up to the programmer.
There is no help by the compiler.
Therefore, there is absolutly no difference between
TFigure = record
X : TShapeList;
case TShapeList of
Rectangle: (Height, Width: Real);
Triangle: (Side1, Side2, Angle: Real);
Circle: (Radius: Real);
Ellipse, Other: ();
end;
and
TFigure = record
case X : TShapeList of
Rectangle: (Height, Width: Real);
Triangle: (Side1, Side2, Angle: Real);
Circle: (Radius: Real);
Ellipse, Other: ();
end;
It ends up in the same record and also the programmer does not see any
difference. He can store whatever he wants in X in both cases. It has no
influences on the variants.
More information about the fpc-pascal
mailing list