| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY 
共有 249 人关注过本帖
标题:枚举在CASE中的使用问题
收藏  订阅  推荐  打印 
liuqiang_sy
Rank: 2
等级:注册会员
帖子:57
积分:674
注册:2007-3-13
枚举在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-4-4 21:27
anthony634
Rank: 12Rank: 12Rank: 12
来自:西南交大
等级:版主
威望:19
帖子:616
积分:6688
注册:2006-6-8

你有不少是拼写的问题啊,最后面哪个,我改了下可以运行了。

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
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;
Label1.Color:=clGreen;
end;
5..7:
begin
showmessage('夏天');
s1:=Red;
Label1.Color:=clred;
end;
8..10:
begin
showmessage('秋天');
s1:=Silver;
Label1.Color:=clSilver;
end;
11..12,1:
begin
showmessage('冬天');
s1:=White;
Label1.Color:=clWhite;
end;
else
begin
showmessage('嘿嘿,你是地球人吗?');
s1:=Yellow;
end;
end;
case s1 of
Green:
Label1.Caption:='春天';
Red:
Label1.Caption:='夏天';
Silver:
Label1.Caption:='秋天';
White:
Label1.Caption:='冬天';
else
label1.Color:=clBlack;
end;
end;
end.

[此贴子已经被作者于2007-4-4 21:44:29编辑过]


承接网络推广,网文发布
http://www.zhouxingwei.cn/Index.html
2007-4-4 21:43
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.051119 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved