首页 > 编程语言 > 详细

枚举类型互相转换(使用GetEnumName和TypeInfo两个函数)

时间:2016-03-19 00:42:41      阅读:383      评论:0      收藏:0      [点我收藏+]

uses
Classes,TypInfo ;


type
TCommandType = (ctEmptyCommand,ctAdd,ctModify);

TCommandTypeConvert=class
public
    class function CommandToString(ACommand: TCommandType): string;
    class function StringToCommand(const AStrCommand: string): TCommandType;
end;

implementation


class function TCommandTypeConvert.CommandToString(ACommand: TCommandType): string;
begin
Result := GetEnumName(TypeInfo(TCommandType),Ord(ACommand));
end;

class function TCommandTypeConvert.StringToCommand(const AStrCommand: string): TCommandType;
begin
Result := TCommandType(GetEnumValue(TypeInfo(TCommandType), AStrCommand));
end;


end. 

http://blog.csdn.net/tercel99/article/details/7791652

枚举类型互相转换(使用GetEnumName和TypeInfo两个函数)

原文:http://www.cnblogs.com/findumars/p/5294102.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!