当前位置:主页>销售管理软件> 列表

罕见枚举类型用法在编译的时候提示错误,那位大侠指教一下。 找用友财务软件u8报价

仓库管理软件版1楼: TCondition = (e1,e2=2);

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

begin
//

ShowMessage(GetEnumName(TypeInfo(TCondition), Ord(1)));
ShowMessage(inttostr(GetEnumValue(TypeInfo(TCondition), ''e1'')));
end

2楼: 看帮助吧,里面说的很详细了

Type ''%s'' has no type info (E2134)

You have applied the TypeInfo standard procedure to a type identifier which does not have any run-time type information associated with it.

program Produce;

type
Data = record
end;

var
v : Pointer;

begin
v := TypeInfo(Data);
end.

Record types do not generate type information, so this use of TypeInfo is illegal.
program Solve;

type
Base = class
end;

var
v : Pointer;

begin
v := TypeInfo(Base);
end.

A class does generate RTTI, so the use of TypeInfo here is perfectly legal. 如用友财务软件u8报价

3楼: 提示什么错误呢

4楼: 换成这样就通过了,不知道为什么。
type
TTestTypeInfo = (e1, e2, e3);

procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(GetEnumName(TypeInfo(TTestTypeInfo), Ord(1)));
ShowMessage(IntToStr(GetEnumValue(TypeInfo(TTestTypeInfo), ''e1'')));
end;

5楼: 估计是这行报错:TCondition = (e1,e2=2);
delphi好像不能人为指定枚举元素的索引值

另外:ord(1)这句话的值不就是1吗,干吗要这么写?ord里面因该放具体的枚举变量

6楼: TTestTypeInfo = (e1=0, e2=1, e3=2);
从0按顺序来就行。

仓库管理软件版7楼: 问题是TTestTypeInfo = (e1=0, e2=1, e3=2);这种写法编译通不过,呵呵。可能delphi不支持这种写法

8楼: 帮顶!

╭=========================================╮

80G海量源代码,控件,书籍全免费狂下不停!

http://www.source520.com

╰=========================================╯