[fpc-pascal] Case in Record

Jürgen Hestermann juergen.hestermann at gmx.de
Tue Oct 6 18:58:07 CEST 2009


> Thank you. I saw all the examples you gave, but I still cannot master
> how to use a variant record without a specified tag.

If you use a specific tag as in

type TFigure = record
                case ShapeName : TShapeList of
                   Rectangle: (Height, Width: Real);
                   Triangle: (Side1, Side2, Angle: Real);
                   Circle: (Radius: Real);
                   Ellipse, Other: ();
                   end;

then you will get an additional part in your record named "ShapeName" 
which can (but not necessarily must) be used to store the meaning of the 
record variants. If you don't use such a variable name as in

type TFigure = record
                case TShapeList of
                   Rectangle: (Height, Width: Real);
                   Triangle: (Side1, Side2, Angle: Real);
                   Circle: (Radius: Real);
                   Ellipse, Other: ();
                   end;

then you have to detect the meaning of the variants in some other way. 
In both cases you can directly access the variants as in 
TFigure.Triangle or TFigure.Rechtangle. But if you stored with one 
variant and read with another you will get a lot of mess. ;-)




More information about the fpc-pascal mailing list