[fpc-pascal] Case in Record

章宏九 secludedsage at gmail.com
Tue Oct 6 21:14:46 CEST 2009


I see. That means if no tag name is given, I should make sure my code
is correct by myself.

Thank you.

2009/10/7 Anton Tichawa <anton.tichawa at chello.at>:
> 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 at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>



More information about the fpc-pascal mailing list