标题:枚举在CASE中的使用问题
取消只看楼主
liuqiang_sy
Rank: 1
等 级:新手上路
帖 子:57
专家分:0
注 册:2007-3-13
 问题点数:0 回复次数:0 
枚举在CASE中的使用问题

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.

搜索更多相关主题的帖子: CASE 枚举 
2007-04-04 21:27



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-129292-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.236561 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved