使用TypeInfo函数时出现has no type info的问题,如何解决? ( 积分: 100 )

  • 主题发起人 主题发起人 tomwld
  • 开始时间 开始时间
T

tomwld

Unregistered / Unconfirmed
GUEST, unregistred user!
unit IMDefs;

interface

uses Classes,TypInfo;

type
TOPCode = (
OPCODE_CS_USERLOGIN = 1,
OPCODE_CS_USERLOGOUT = 2,
OPCODE_CS_CHANGESTATUS = 7,
OPCODE_CS_GETSTATUS = 8,
OPCODE_CS_SENDMSG = 9,
OPCODE_CS_ADDGROUP = 10,
OPCODE_CS_REMOVEGROUP = 11,
OPCODE_CS_VIEWGROUP = 12,
OPCODE_CS_UPDATEGROUP = 13,
OPCODE_CS_QUERYGROUPLIST = 14,
OPCODE_CS_ADDFRIEND = 15,
OPCODE_CS_ADDTOBLANKLIST = 16,
OPCODE_CS_INVITE = 17,
OPCODE_CS_ACCEPTINVITE = 18,
OPCODE_CS_KICKUSER = 19,
OPCODE_CS_CREATEROOM = 20,
OPCODE_CS_REMOVEROOM = 21,
OPCODE_CS_LOCKROOM = 22,
OPCODE_CS_UNLOCKROOM = 23,
OPCODE_CS_QUERYGROUPUSERLIST = 24,
OPCODE_CS_REMOVEFRIEND = 25,
OPCODE_CS_UPDATEFRIENDGROUP = 26,
OPCODE_CS_SEARCHUSER = 27,
OPCODE_CS_SEARCHUSERBYPAGE = 28,
OPCODE_CS_GETONLINEUSERCOUNT = 29,
OPCODE_CS_MAX = 499
);


使用:OPCode := TOPCode(GetEnumValue(TypeInfo(TOPCode), cbbOpCode.Text));编译时出现如上错误
 
unit IMDefs;

interface

uses Classes,TypInfo;

type
TOPCode = (
OPCODE_CS_USERLOGIN = 1,
OPCODE_CS_USERLOGOUT = 2,
OPCODE_CS_CHANGESTATUS = 7,
OPCODE_CS_GETSTATUS = 8,
OPCODE_CS_SENDMSG = 9,
OPCODE_CS_ADDGROUP = 10,
OPCODE_CS_REMOVEGROUP = 11,
OPCODE_CS_VIEWGROUP = 12,
OPCODE_CS_UPDATEGROUP = 13,
OPCODE_CS_QUERYGROUPLIST = 14,
OPCODE_CS_ADDFRIEND = 15,
OPCODE_CS_ADDTOBLANKLIST = 16,
OPCODE_CS_INVITE = 17,
OPCODE_CS_ACCEPTINVITE = 18,
OPCODE_CS_KICKUSER = 19,
OPCODE_CS_CREATEROOM = 20,
OPCODE_CS_REMOVEROOM = 21,
OPCODE_CS_LOCKROOM = 22,
OPCODE_CS_UNLOCKROOM = 23,
OPCODE_CS_QUERYGROUPUSERLIST = 24,
OPCODE_CS_REMOVEFRIEND = 25,
OPCODE_CS_UPDATEFRIENDGROUP = 26,
OPCODE_CS_SEARCHUSER = 27,
OPCODE_CS_SEARCHUSERBYPAGE = 28,
OPCODE_CS_GETONLINEUSERCOUNT = 29,
OPCODE_CS_MAX = 499
);


使用:OPCode := TOPCode(GetEnumValue(TypeInfo(TOPCode), cbbOpCode.Text));编译时出现如上错误
 
typeInfo是什么类???uses 是用来引用单元的
 
看看帮助吧
Delphi Language Reference
Enumerated types

Topic Groups See Also

....

Note

Enumerated constants without a specific value have RTTI:

type SomeEnum = (e1, e2, e3);

whereas enumerated constants with a specific value, such as the following, do not have RTTI:

type SomeEnum = (e1 = 1, e2 = 2, e3 = 3);
 
明白了,谢谢
 
指定了值的枚举类型是没有 RTTI 的,不过你的问题可以变相解决:
TOPCode = (
OPCODE_CS_USERLOGIN,
OPCODE_CS_USERLOGOUT,
OPCODE_CS_CHANGESTATUS,
...
);
OpCodeValues: array [TOPCode] of Integer = (
1,
2,
7,
...
);
然后:
OPCode := OpCodeValues[TOPCode(GetEnumValue(TypeInfo(TOPCode), cbbOpCode.Text))];
即可。
 
明白了,谢谢
 
多人接受答案了。
 
后退
顶部