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;

相关阅读 >>

Delphi循环移位操作

Delphi 如何按下esc键退出程序

Delphi 高亮选中memo某一行

Delphi 动态修改显示器分辨率

Delphi 选择目录对话框(selectdirectory 函数)

Delphi运行时拖拉、改变元件大小

Delphi编写iis过滤器实例

Delphi 字符串去掉最后一个字符

Delphi 缓冲文件流-tbufferedfilestream tfilestream 性能测试

Delphi 批量生成 a到z 字母

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...