Delphi 中的 IfThen 函数 - 回复 "深挖洞、广积粮" 的问题
2008-11-14 15:23
585 查看
问题来源: http://www.cnblogs.com/del/archive/2008/11/14/1120015.html#1370413
StrUtils 单元和 Math 单元 分别有一个 IfThen 函数, 举例:
StrUtils 单元和 Math 单元 分别有一个 IfThen 函数, 举例:
unit Unit1; interface uses 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.
相关文章推荐
- 读文件到十六进制的函数(Delphi 7 下可用) - 回复 "峰哥!!!" 的问题
- Delphi 中的 IfThen 函数
- Delphi 中的 IfThen 函数
- orcale单行函数之Case, decode在 SQL 语句中使用IF-THEN-ELSE 逻辑
- delphi 常用函数和常见问题的解决方案(更新中......)
- 关于Delphi在定义了函数进行调用时显示undeclared identifier的问题
- Delphi使用C++库,向库中函数传递回调函数指针的问题解决
- 如何使用 URLOpenStream 函数 - 回复 "天泽" 的问题
- 浅谈C语言 if else, switch, 条件运算符, 函数指针的选择问题
- 合并两个 Wav 文件流的函数 - 回复 "刘文强" 的问题
- 输出用空格对齐字符串的函数 - 回复 "老A123" 的问题
- Delphi中使用@取函数地址的问题
- Delphi的三目运算 ifthen 和iif
- 给 Edit 两个可选值 - 回复 "delphi学习中" 的问题
- 慎用IfThen函数!
- Delphi中使用@取函数地址的问题
- Delphi中使用@取函数地址的问题(转)
- 使用 idHTTP 获取 UTF-8 编码的中文网页 - 回复同学 "Delphi学习者" 的问题
- 关于TChrome中加载JS与delphi交互问题,回复liqiao的提问
- 用 MapFileAndCheckSum 函数检测 exe 或 dll 是否被修改 - 回复 "Joe Lo" 的问题