好像在Pascal語言里有這樣一個語法:
b:= if( a>1,2,3)
就像Excel里寫公式一樣,但是在Delphi里就是行不通,請間該怎么寫?
我只想要一句最簡單的代碼實現,不想要比如:
if a>1 then b:=2 eles b:=3;
也許沒有說清楚:(
b:= if( a>1,2,3)
就像Excel里寫公式一樣,但是在Delphi里就是行不通,請間該怎么寫?
我只想要一句最簡單的代碼實現,不想要比如:
if a>1 then b:=2 eles b:=3;
也許沒有說清楚:(
解决方案 »
- DDELPHI中如何将一个数据库表中的时间列用另一个数据库表中的时间列替换 表A TIME1 表B TIME2
- 运行时,会提示违反了PRRIMARY KEY 不能在对象里添加错误 我如何返回到原来的界面??
- 对于一组动态生成的控件如何获得当前活动控件的名字
- 数据库与图片问题.
- 如何,在2个窗口中交换数据啊。
- 想了解一下大家一般使用什么控件做报表?
- 各位高手介绍一些dbExpress好吗
- 以下录音程序有问题??
- delphi是一种啥语言,有啥用?
- 哪里有Tobur pascal可以下载?
- 数据包vDatas中包含有主/细表数据,如何用代码将MIDAS数据包vDatas中的detail表的数据指定给Tdataclient控件?
- javascript调用activex的时候能不能等待程序结束再往下面执行?
不过你完全可以自己写一个这样的函数。
b:= if( a>1,2,3)c里面有一个类似的b= a>1 ? 2: 3;
begin
if a then
result:= b
else
result:= c;
end;
。。
b:= iif( a>1,2,3);
asm
test EAX,EAX
jnz @True
mov EAX,ECX
ret
@True:
mov EAX,EDX
ret
end;
Conditionally returns one of two specified values.UnitMathStrUtils or Categorymiscellaneous routinesDelphi syntax:function IfThen(AValue: Boolean; const ATrue: Integer; const AFalse: Integer = 0): Integer; overload
;function IfThen(AValue: Boolean; const ATrue: Int64; const AFalse: Int64 = 0): Int64; overload;
function IfThen(AValue: Boolean; const ATrue: Double; const AFalse: Double = 0.0): Double; overload;
function IfThen(AValue: Boolean; const ATrue: string; const AFalse: string = ''): string; overload;C++ syntax:extern PACKAGE int __fastcall IfThen(bool AValue, const int ATrue const int AFalse);
extern PACKAGE __int64 __fastcall IfThen(bool AValue, const __int64 ATrue const __int64 AFalse);
extern PACKAGE double __fastcall IfThen(bool AValue, const double ATrue const double AFalse);
extern PACKAGE AnsiString __fastcall IfThen(bool AValue, const AnsiString ATrue const AnsiString AFalse);DescriptionIfThen checks the expression passed as AValue and returns ATrue if it evaluates to true, or AFalse if it evaluates to false. In Delphi, if the AFalse parameter is omitted, IfThen returns 0 or an empty string when AValue evaluates to False.
比如:
IsLeapYear,判断是否是闰年;
DaysBetween,求两个日期相隔天数;
DaysInMonth,
DaysInAMonth,
DaysInYear,
....
还有数学运算函数
...
等等,好多好多,大家一起来。
b = a > 1 ? 1:3 这是c里才有的
delphi 里老老实实的:
if a > 1 then b := 1
else b := 3
ok!
很多这样函数平时很多人都会忽视的。即使要用的时候,也不知道怎么找出这样的函数。