delphi 自带一个奇怪语句可以实现
Conditionally returns one of two specified values.
Unit
MathStrUtilsor
Category
miscellaneous routines
Delphi 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);
Description
IfThen 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.