- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
delphi case of
uses
Character;
procedure TForm1.Button1Click(Sender: TObject);
var
number: Integer;
aText: string;
begin
number := Trunc(NumberBox1.Value);
case number of
1: aText := 'One';
2: aText := 'Two';
3: aText := 'Three';
end;
if aText <> '' then
Show(aText);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
aChar: Char;
aText: string;
begin
/// multiple nested if statements
if Edit1.Text.Length > 0 then
begin
aChar := Edit1.Text.Chars[0];
case aChar of
'+' : aText := 'Plus sign';
'-' : aText := 'Minus sign';
'*', '/': aText := 'Multiplication or division';
'0'..'9': aText := 'Number';
'a'..'z': aText := 'Lowercase character';
'A'..'Z': aText := 'Uppercase character';
#12032..#12255: aText := 'Kangxi Radical';
else
aText := 'Other character: ' + aChar;
end;
Show(aText);
end;
end;
procedure TForm1.Show(const msg: string);
begin
Memo1.Lines.Add(msg);
end;