On Tue, 2009-10-06 at 23:37 +0800, 章宏九 wrote: > Thank you. I saw all the examples you gave, but I still cannot master > how to use a variant record without a specified tag. > > For example: > type > TShapeList = (Rectangle, Triangle, Circle, Ellipse, Other); > TFigure = record > case TShapeList of > Rectangle: (Height, Width: Real); > Triangle: (Side1, Side2, Angle: Real); > Circle: (Radius: Real); > Ellipse, Other: (); > end; > var > Figure1: TFigure; >
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. This saves memory ("TShapeList" has no memory reserved at run time), but the program is responsible to correctly identify the variant using the "name" field. Anton _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal