case integer of
varsmallint:(vsmallint:smallint);
varDouble:(vdouble:Double); 刚学不太明白cases语句的用法希望帮我注释写的详细点,在帮我写几个case语句的例子学习下,谢了
varsmallint:(vsmallint:smallint);
varDouble:(vdouble:Double); 刚学不太明白cases语句的用法希望帮我注释写的详细点,在帮我写几个case语句的例子学习下,谢了
case i of
0: ADOTable1.FieldByName('pid').AsString:= '0';//对应***部
1: ADOTable1.FieldByName('pid').AsString:= '1';//对应人事部
2: ADOTable1.FieldByName('pid').AsString:= '2';//财务部
3: ADOTable1.FieldByName('pid').AsString:= '3';//技术部
6..9: Caption := 'High';
0, 10..99: Caption := 'Out of range';
else
Caption := '';
end;===============================if I in [1..5] then Caption := 'Low'
else if I in [6..10] then
Caption := 'High'
else if (I = 0) or (I in [10..99]) then
Caption := 'Out of range'
else
Caption := '';==================================case MyColor of Red: X := 1;
Green: X := 2;
Blue: X := 3;
Yellow, Orange, Black: X := 0;
end;
case 表达式 of
值表 1:语句1;
值表 2:语句2;
。。 值表n;语句n;
end;
0: begin
// do something 0
end;
1: begin
// do something 1
end;
2: begin
// do something 2
end;
3: begin
// do something 3
end;
4: begin
// do something 4
end;
5: begin
// do something 5
end
else begin
// do other stings
end;
end;
unit Unit1;interfaceuses
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;var
Form1: TForm1;implementation{$R *.dfm}
procedure casei(var i:integer);
begin
case i of
0:form1.caption:='can not be zero';
1..5:form1.caption:='low';
6..9:form1.caption:='hight';
10..99:form1.caption:='out of range';
else
form1.caption:='';
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
i:=0;
casei(i);
end;end.
刚刚给你写一个例子。
给i赋不同的值,窗体的名称会不同,你试试
unit Unit1;interfaceuses
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;var
Form1: TForm1;implementation{$R *.dfm}
procedure casei(i:integer);
begin
case i of
0:form1.caption:='can not be zero';
1..5:form1.caption:='low';
6..9:form1.caption:='hight';
10..99:form1.caption:='out of range';
else
form1.caption:='';
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
casei(98);
end;end.
给i赋不同的值,窗体的名称会不同,你试试
稍微更正了一下,用这个吧,楼主
unit Unit1;interfaceuses
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;var
Form1: TForm1;implementation{$R *.dfm}
procedure casei(i:integer);
begin
case i of
0:form1.Button1.Caption:='谁能弄死我';
1..5:form1.Button1.Caption:='我能弄死我';
6..9:form1.Button1.Caption:='谁弄死我试试';
10..99:form1.Button1.Caption:='我弄死你咋地';
else
form1.caption:='';
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
casei(98);
end;end.
来个中文的,好看一点,把按钮的宽和高弄大一些[/code]