What is the most elegant (or least ugly) way to use typed constants in a case in Delphi?
That is, suppose for this question that you need to declare a typed constant, as in
const MY_CONST: cardinal = $12345678; ...
Then the Delphi compiler will not accept
case MyExpression of MY_CONST: { Do Something }; ... end;
but you need to write
case MyExpression of $12345678: { Do Something }; ... end;
which is error prone, is hard to update, not elegant.
Is there any trick you can use to force the compiler to insert a constant value (preferably by checking the constant value in const in the source code, but perhaps by looking at the value at runtime)? We assume that you will not change the value of "constant" at runtime.
delphi case-statement
Andreas Rejbrand
source share