[fpc-pascal] Associate initializer value with array item type

cobines cobines at gmail.com
Thu Mar 24 23:43:32 CET 2011


Let's say I have a type:

TClothingType = (ctJacket, ctPants, ctShirt);

and I want to associate it with color:

  Colors: array[TClothingType] = (clRed, clBlue, clGreen);

Is it possible to protect Colors against a change in order of items in
TClothingType? Adding or removing items from TClothingType will
generate error that too much/not enough initializers are present. But
if someone changes the order of items or changes a clothing type to
different I will get wrong association of colors.

I'm thinking of syntax like this:

  Colors: array[TClothingType] = (ctJacket:clRed, ctPants:clBlue,

Is something like this possible?

I know I can assign it at runtime:

Colors[ctJacket] := clRed;
Colors[ctPants] := clBlue;
Colors[ctShirt] := clGreen;

But I'm looking for compile time method.


More information about the fpc-pascal mailing list