16,748
社区成员
发帖
与我相关
我的任务
分享
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls ;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TCommandType = (ctEmptyCommand,ctAdd,ctModify);
var
Form1: TForm1;
implementation
uses TypInfo;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);//函数应用:
var v: TCommandType;
v_int:integer;
begin
v:=ctAdd;
v_int:=2;
//枚举类型的值得到数字:
showmessage(inttostr(ord(v)));
//数字得到枚举类型值的名:
showmessage( GetEnumName(TypeInfo(TCommandType),v_int));
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, TypInfo ;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TCommandType = (ctEmptyCommand, ctAdd, ctModify);
TCommandTypeConvert=class
public
class function CommandToString(ACommand: TCommandType): string;
class function StringToCommand(const AStrCommand: string): TCommandType;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
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;
procedure TForm1.Button1Click(Sender: TObject);//函数应用:
var v: TCommandType;
begin
v:=ctAdd;
//枚举类型的值得到数字:
showmessage(inttostr(ord(v)));
//数字得到枚举类型值的名:
showmessage(TCommandTypeConvert.CommandToString(TCommandType(1)));
end;
end.