Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 561671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:28:26+00:00 2026-05-13T12:28:26+00:00

I kept my hands off Delphi for too long, I guess; busied myself with

  • 0

I kept my hands off Delphi for too long, I guess; busied myself with Java and PHP a lot over the last couple of years. Now, when I got back to doing a little Delphi job, I realised I really miss the conditional operator which is supported by both Java and PHP.

On how many places would you find lines like these in your Delphi programs?

var s : string;
begin
  ...<here the string result is manipulated>...

  if combo.Text='' then
      s := 'null'
    else
      s := QuotedStr(combo.Text);

  result := result + s;
end;

where a simple

result := result + (combo.text='')?'null':quotedStr(combo.text);

would suffice. What I like about this is that it not only shortens the code, this way I also avoid declaring some helper s:string variable.

Why are conditional operators not part of Delphi and – are they ever going to be supported? I noticed there were quite a few language extensions made for the 2009 version of Delphi (generics), so why not add this feature?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:28:27+00:00Added an answer on May 13, 2026 at 12:28 pm

    Such an operator isn’t part of the current Delphi version because it wasn’t part of the previous version, and demand wasn’t great enough to justify the cost of adding it. (You’ll find that explanation applies to lots of features you wish you had in lots of products.)

    Delphi provides a set of IfThen functions in the Math and StrUtils units, but they have the unfortunate property of evaluating both their value parameters, so code like this will fail:

    Foo := IfThen(Obj = nil, '<none>', Obj.Name);
    

    To really do it right, there needs to be help from the compiler. Within the Delphi community, I sense a general dislike of the C-style syntax using a question mark and a colon. I’ve seen proposals that would use syntax like this:

    Foo := if Obj = nil then
             '<none>'
           else
             Obj.Name;
    

    Part of what makes conditional operators so attractive is that they let you write concise code, but Delphi’s style of writing everything out makes the above unappealing, even if put all on one line.

    It doesn’t really need to be in the form of an operator. Delphi Prism provides a compiler-magic function Iif that only evaluates one of its two value parameters:

    Foo := Iif(Obj = nil, '<none>', Obj.Name);
    

    You asked why a feature like this wouldn’t have been added along with all the other language features added in Delphi 2009. I think that’s your reason. There were plenty of other language changes going on that already required delicate handling; the developers didn’t need to be burdened with even more. Features aren’t free.

    You asked whether Delphi will ever have such a feature. I’m not privy to Embarcadero’s planning meetings, and I had to send my crystal ball away for repairs, so I can’t say for certain, but I predict that if it ever would have such a feature, it would come in the form of Delphi Prism’s Iif function. That idea shows up near the end of the discussion in Quality Central, and an objection is made that, as a new reserved word, it would break backward compatibility with other people’s code that already defines a function with the same name. That’s not a valid object, though, because it wouldn’t need to be a reserved word. It could be an identifier, and just like Writeln and Exit, it can be eligible to be redefined in other units even though the one from the System unit is treated specially.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I kept thinking a lot about the meaning of migrating a Django app the
I'm trying to touch all potential dealer hands in blackjack, but when I kept
This problem has kept me busy for the last hours. I have two sections
I've created a couple of little few page long websites for one time projects
Kept on seeing this pattern in code, but couldn't find any reference to it
I kept 2 asp panel controls (with text boxes and buttons) in an update
I kept on receiving this error Deprecated: Assigning the return value of new by
Disclaimer : I kept this because some things may be useful to others, however,
I have kept hearing this statement. Switch..Case is Evil for code maintenance, but it
If HTTP persistent connection is kept alive and done on the same socket with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.