获取Delphi中定义的枚举类型的名称和值
2007-11-08 10:13
183 查看
利用TypInfo单元的GetEnumName和GetEnumValue可以遍历任意枚举类型,并获取其名称和值。下面是示例Demo。
procedure TForm1.btnTestClick(Sender: TObject);
var
p: PTypeData;
i: Integer;
s: String;
pt: PTypeInfo;
begin
ListBox1.Items.Clear;
pt := TypeInfo(TWindowState);
if pt.Kind <> tkEnumeration then begin
ShowMessage('不是枚举类型');
Exit;
end;
p := GetTypeData(TypeInfo(TWindowState));
//将获取的枚举类型信息,以枚举名=枚举值的形式加入到ListBox中
ListBox1.Items.beginUpdate;
try
for i := p.MinValue to p.MaxValue do begin
S := GetEnumName(pt,i);
ListBox1.Items.Values[S] := IntToStr(GetEnumValue(pt, S));
end;
finally
ListBox1.Items.EndUpdate;
end;
end;
procedure TForm1.btnTestClick(Sender: TObject);
var
p: PTypeData;
i: Integer;
s: String;
pt: PTypeInfo;
begin
ListBox1.Items.Clear;
pt := TypeInfo(TWindowState);
if pt.Kind <> tkEnumeration then begin
ShowMessage('不是枚举类型');
Exit;
end;
p := GetTypeData(TypeInfo(TWindowState));
//将获取的枚举类型信息,以枚举名=枚举值的形式加入到ListBox中
ListBox1.Items.beginUpdate;
try
for i := p.MinValue to p.MaxValue do begin
S := GetEnumName(pt,i);
ListBox1.Items.Values[S] := IntToStr(GetEnumValue(pt, S));
end;
finally
ListBox1.Items.EndUpdate;
end;
end;
相关文章推荐
- 通过反射获取struct中定义的Field的名称和值
- Android 通过resource名称或者layout中定义的id name 去获取R.java中id,得到控件
- 黄聪:Delphi 中的 XMLDocument 类详解(7) - 获取节点名称与节点的属性名称
- Delphi获取默认打印机名称及端口
- 获取所有命名的服务器变量的名称和值
- delphi 获取ODBC DSN名称
- C#中循环获取枚举中的名称和值
- Delphi获取默认打印机名称及端口
- C#获取EF实体对象或自定义属性类的字段名称和值
- 获取硬件信息的delphi源码(CPUID、操作系统、Mac物理地址、计算机名称、IP地址、用户名)
- Delphi 7里Messages.pas里所有104种重定义消息种类,180种不同的消息名称
- Delphi中获取某类的祖先类及其所在单元名称
- 获取httpservletrequest所有参数的名称和值
- 获取枚举类型的 中文 描述 和值
- js 获取函数的所有参数和遍历JavaScript某个对象所有的属性名称和值的方法
- Delphi中获取某类的祖先类及其所在单元名称
- delphi 通过点击获取控件名称
- C#获取EF实体对象或自定义属性类的字段名称和值
- Delphi枚举类型通过下标获取类型和通过类型获取下标方法
- Delphi 中的 XMLDocument 类详解(7) - 获取节点名称与节点的属性名称