You can use a multidimensional constant array with an enumeration for at least one of the dimensions:
Define this as follows:
type TKVEnum = (tKey, tValue); // You could give this a better name const Count = 3; KeyValues: array [1..Count, TKVEnum] of string = // This is each of your name / value paris (('1', 'a'), ('2', 'b'), ('3', 'd'));
Then you use it as follows:
if MyValue = KeyValues[1, TKVEnum.tKey] then Result := KeyValues[1, TKVEnum.tValue]
You can use the For loop. This is just as effective as their individual constant lines, but gives you the added advantage that they are related to each other.
Instead of defining the first dimension numerically, I would suggest
type TConstPairs = (tcUsername, tcDatabase, tcEtcetera);
But I think that it completely depends on what you imagine.
Jim mckeeth
source share