2009/10/6 章宏九 <secludeds...@gmail.com>: > 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; > > How can I specified the TShapelist value in a Figure1?
You can specify an identifier in the case statement, which will become a new field. You can then specify what the record is used for currently, e.g.: TShapeList = (Rectangle, Triangle, Circle, Ellipse, Other); TFigure = record case Shape: TShapeList of ^^^^^^^ Rectangle: (Height, Width: Real); Triangle: (Side1, Side2, Angle: Real); Circle: (Radius: Real); Ellipse, Other: (); end; Then you can set .Shape to Rectangle, for instance, and fill in .Height and .Width. A function receiving a variable of this record can then see what shape it is currently used for. You need to maintain this .Shape field, though. Henry _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal