views:

88

answers:

1

Using Delphi 2007 I can write the following code:

interface
TTestType = (ttTest1, ttTest2);

procedure enumName;
var
  EnumName: String;
begin
  EnumName := GetEnumName(TypeInfo(TTestType), Ord(ttTest1));
end;

This compiles and works, EnumName contains 'ttTest1' at the end of the function.

However, when I change my TTestType to something like this:

interface
TTestType = (ttTest1=1, ttTest2=2);

My code suddenly won't compile anymore. [DCC Error] Test.pas(271): E2134 Type 'TTestType' has no type info

Now I can make a const array of string with the enum names, but I find this a dirty solution. Can anybody point me in the right direction or am I trying something impossible here?

+1  A: 

I don't see any difference between the snippets, but assume that you did something like "ttype=(x=1,y=2);". That would prevent Delphi from generating RTTInformation. It's a compiler limitation at least until D2010.

Loxley
That's what I meant, edited.
Roald van Doorn