Link to home
Start Free TrialLog in
Avatar of ocean9
ocean9

asked on

Immediate IIF()

Hi all,
I am trying to write an IIF function (like one in C ?: and Access) in Delphi 3.0. Any help would be appreciated.

construct:  IIF( <logical expr.>, <TruePart>, <FalsePart>)

example: x := IIF( x > y, 100, 50)
equivalent to
If x > y then
  x := 100
else
  x := 50;
ASKER CERTIFIED SOLUTION
Avatar of Epsylon
Epsylon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CalvinDay
CalvinDay

function IIF(test:boolean;iftrue,iffalse:integer);
begin
  if test then
    Result:=iftrue
  else
    Result:=iffalse;
end;
eps, your're too quick!

the Variant was a nice touch.
Another way is overloading but you need to implement a function for each type this way.....

CalvinDay, sorry    :o)
Avatar of simonet
>the Variant was a nice touch.
Yeap! I thought that too.
Alex
Avatar of ocean9

ASKER

Thanks Epsylon and you too CalvinDay.