unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
type
Tcolor=(Yellow,Orange,Green,Black,Red,Silver,White); //这里我定了一个枚举类型.
{$R *.dfm}
var
m1:integer;
s1:Tcolor; //定义一个枚举类型的变量
procedure TForm1.Button1Click(Sender: TObject);
begin
m1:=strtoint(inputbox('月份转季节','请输入月份','1'));
case m1 of
2..4:
begin
showmessage('春天');
s1:=Green;
end;
5..7:
begin
showmessage('夏天');
s1:=Red;
end;
8..10:
begin
showmessage('秋天');
s1:=Silver;
end;
11..12,1:
begin
showmessage('冬天');
s1:=White;
end;
else
begin
showmessage('你不是地球人吗?');
s1:=Yellow;
end;
end
case s1 of
Green:
Label1.Caption:='春天';
Red:
Label1.Caption:='夏天';
Silver:
Label1.Caption:='秋天';
White:
Label1.Caption:='冬天';
end
label1.Color:=s1;
end;
end.