Greeting!
I am seeking a generic way which can retrieve an enumeration value as string representation instead of its integer value.
Given below code:
...
const
genArr:array [0..1] of string=('male','female');
type
Gender=(male,female);
function genStr(gen:Gender):string;
begin
result:=genArr[integer(gen)];//==>is there a generic function to do so?
end;
begin
writeln('He is ',genStr(male),'.');//output 'He is male.'
writeln('She is ',genStr(female),'.');//output 'She is female.'
readln;
end.
It works as expected,properly print the string representations of emumeration value;however if there is a more generic (templated) way to archieve this ,it will be great.
Any idea would be appreciated.
Regards,
Sam