Delphi中的GetEnumName和GetEnumValue的使用方法
2014-04-06 08:03
246 查看
利用TypInfo单元的GetEnumName和GetEnumValue可以遍历任意枚举类型,并获取其名称和值。下面是示例Demo。
uses TypInfo;
...
uses TypInfo;
...
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;
相关文章推荐
- 使用GetEnumName和GetEnumValue获取枚举类型的名称和数值
- GetItemValue、Itemname使用方法
- Div使用name属性实现通过getElementsByName获取Div集的方法
- 使用InetAddress类的getHostName方法获得域名
- IOCP中使用getpeername出错,返回10014的解决方法。
- 使用InetAddress类的getHostName方法
- 【分享】【js中的document.getElementsByName()方法的使用】
- 如何在mapreduce方法中获取当前使用文件(get file name)
- configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));错误解决方法
- 关于jQ中$(selector).data(name,value)方法的使用
- filegetname方法+filegetname(desc_bfile,directory,filename)+使用filegetname方法
- configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));错误解决方法
- document.getElementById("").style和$("").css(name,value)方法的区别?
- 谷歌浏览器document.getElementsByName方法不能使用
- Java网络编程从入门到精通(5):使用InetAddress类的getHostName方法获得域名
- C#+Enum 枚举扩展方法获取name,value和Description
- 使用getCanonicalHostName方法获得主机名
- Java网络编程从入门到精通(6):使用getCanonicalHostName方法获得主机名
- Java网络编程从入门到精通(5):使用InetAddress类的getHostName方法获得域名
- jquery之操作元素属性和特性(设置特性值,attr(name,value),attr(attributes)方法的使用)