if StrToIntDef(Edit1.Text, 0) in (1,2,3) then ....
这种题用case判别就行,无须用到集合.这里用集合反而麻烦
我尝试用集合的写法,,type Season =set of 1..12;var Spring,Summer,Autumn,Winter:Season;Spring := [1,2,3]; Summer := [4,5,6]; Autumn := [7,8,9]; Winter := [10,11,12];V := StrToIntDef(Edit1.Text, 0); if V in Spring then .. elseif V in Summer then .. elseif V in Autumn then .. elseif V in Winter then .. else ..
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
r:array[1..9] of string=('春天','春天','春天','夏天','夏天','夏天','冬天','冬天','冬天');
implementation{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(r[strtoint(edit1.Text)]);
//edit2.Text:=r[strtoint(edit1.Text)];
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TseasonType = (stSpring, stSummer, stAutumn, stWinter);type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
seasonType: TseasonType ;
begin
case (StrToIntDef(Edit1.Text, 0)) of
1,2,3: seasonType := stSpring ;
4,5,6: seasonType := stSummer ;
7,8,9: seasonType := stAutumn ;
10,11,12: seasonType := stWinter ;
end;
end;end.
....
Summer := [4,5,6];
Autumn := [7,8,9];
Winter := [10,11,12];V := StrToIntDef(Edit1.Text, 0);
if V in Spring then ..
elseif V in Summer then ..
elseif V in Autumn then ..
elseif V in Winter then ..
else ..