Given the following enum:
type TEnum = (teA, teB, teC);
I would like to declare a const array of TEnum
, however I find with the following the connection between the array items and enum items is relatively hard to read and maintain (obviously I am aware that I can comment verbosely and give each item its own line):
const AN_ARRAY : array[TEnum] of Integer = (1, 12, 146);
Is there a way to declare a const array more like this?
const
AN_ARRAY : array[TEnum] of Integer :
AN_ARRAY[teA] = 1,
AN_ARRAY[teB] = 12,
AN_ARRAY[teC] = 146
;
Ideally I would like to set the enum ord values and not use the array at all, but this means that I then can't use TypeInfo
to manipulate the enum.
No. The indices of an array constant are always implicit. Include them in comments if you need to see them beside their corresponding values, but beware that the comments may get out of sync with the real code, and the compiler won't warn you about that.
const
AN_ARRAY : array[TEnum] of Integer = (
1, // teA
12, // teB
146 // teC
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With