试一试这个:
Unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
Tmj = (tm1,tm2,tm3,tm4);//声明枚举类型
Tjh = set of tmj;//声明集合类型
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var tmmj : Tmj;//枚举类型
tmjh : Tjh;//集合类型
tmstr : String;
tmmj2 : Tmj;//枚举类型
tmjh2 : Tjh;//集合类型
begin
tmmj := tm1;
tmstr := IntToStr(BYTE(tmmj));
//将枚举类型转化为字符串
tmmj2 := Tmj(BYTE(StrToInt(tmstr)));
//将字符串类型转化为枚举类型
if tmmj2 = tm1 then
ShowMessage('枚举类型转化成功');
tmjh := [tm1,tm3];
tmstr := IntToStr(BYTE(tmjh));//将集合类型转化为字符串
tmjh2 := Tjh(BYTE(StrToInt(tmstr)));
//将字符串类型转化为集合类型
if tm1 in tmjh2 then
ShowMessage('集合类型转化成功');
end;
end.