Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.