打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Delphi 中的 IfThen 函数
问题来源: http://www.cnblogs.com/del/archive/2008/11/14/1120015.html#1370413

StrUtils 单元和 Math 单元 分别有一个 IfThen 函数, 举例:
unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls;type  TForm1 = class(TForm)    Button1: TButton;    Button2: TButton;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);  end;var  Form1: TForm1;implementation{$R *.dfm}uses StrUtils, Math;procedure TForm1.Button1Click(Sender: TObject);var  a: Integer;  str: string;begin  a := 1;  str := StrUtils.IfThen(a > 0, 'aaa', 'bbb');  ShowMessage(str); {aaa}  a := -1;  str := StrUtils.IfThen(a > 0, 'aaa', 'bbb');  ShowMessage(str); {bbb}  a := 1;  str := StrUtils.IfThen(a > 0, 'aaa');  ShowMessage(str); {aaa}  a := -1;  str := StrUtils.IfThen(a > 0, 'aaa');  ShowMessage(str); {}end;procedure TForm1.Button2Click(Sender: TObject);var  str: string;  num: Integer;begin  str := '万一';  num := Math.IfThen(str <> '', 99, 11);  ShowMessage(IntToStr(num)); {99}  str := '';  num := Math.IfThen(str <> '', 99, 11);  ShowMessage(IntToStr(num)); {11}  str := '万一';  num := Math.IfThen(str <> '', 99);  ShowMessage(IntToStr(num)); {99}  str := '';  num := Math.IfThen(str <> '', 99);  ShowMessage(IntToStr(num)); {0}end;end.
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
DelPhi2007 中 使用Indy 的TCP连接教程
Delphi获取内外网IP
谈谈 Delphi 的类型与指针[2]
delphi基础开发技巧
Delphi指针基本知识
Delphi 的接口
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服