开发者

Enumerated types with specified values do not have TypeInfo, why? [duplicate]

This question already has answers here: Why do I get "type has no typeinfo" error with an enum type (3 answers) Closed 8 years ago.

Using Delphi 2007 I can write the following code:

interface
T开发者_开发百科TestType = (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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜