【转】Delphi枚举类型和字符串之间相互转化

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.

posted @ 2017-08-29 14:44  懵逼Coder  阅读(1422)  评论(0)    收藏  举报