delphi中有没有类似于iif(条件,值1,值2)的函数!(100分)

D

doghole

Unregistered / Unconfirmed
GUEST, unregistred user!
[red][/red][:(!]delphi中有没有类似于iif(条件,值1,值2)的函数!

如果条件为真则返回值1
如果条件为假则返回值2
 
delphi6中math单元有一个IfThen函数
 
delphi6新增的函数
IFthen就是如此的。
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;
 
怎么用?

我试过好像不行。

[Error] Unit1.pas(28): Undeclared identifier: 'ifThen'
 
DLEPHI6

要Uses Math;
 
给你个例子:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
CheckBox1: TCheckBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses math;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
i:=IfThen(checkbox1.Checked,1,0);
showmessage(inttostr(I));
end;

end.


这个函数没啥意义,看源码就知道了
 
顶部