Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Immediate IIF()

Posted on 1999-07-19
7
Medium Priority
?
1,111 Views
Last Modified: 2009-12-16
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;
0
Comment
Question by:ocean9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 210 total points
ID: 1389702
Try this:

function IIF(cond: Boolean; t, f: Variant): Variant;
begin
  if cond then
    Result := t
  else
    Result := f;
end;


SpinEdit1.Value := IIF(2<3, 24, 48);  // returns 24
Edit1.Text := IIF(2>3, 'true', 'false'); // returns 'false'


Cheers,

Epsylon.


0
 
LVL 2

Expert Comment

by:CalvinDay
ID: 1389703
function IIF(test:boolean;iftrue,iffalse:integer);
begin
  if test then
    Result:=iftrue
  else
    Result:=iffalse;
end;
0
 
LVL 2

Expert Comment

by:CalvinDay
ID: 1389704
eps, your're too quick!

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:CalvinDay
ID: 1389705
the Variant was a nice touch.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1389706
Another way is overloading but you need to implement a function for each type this way.....

CalvinDay, sorry    :o)
0
 
LVL 15

Expert Comment

by:simonet
ID: 1389707
>the Variant was a nice touch.
Yeap! I thought that too.
Alex
0
 

Author Comment

by:ocean9
ID: 1389708
Thanks Epsylon and you too CalvinDay.

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question