Recent

Author Topic: Ternary operator in Delphi, Too early of a release?  (Read 293 times)

jamie

  • Hero Member
  • *****
  • Posts: 7823
Ternary operator in Delphi, Too early of a release?
« on: July 06, 2026, 11:25:25 pm »
Today at work, we got to play with a newer version of Delphi and I wanted to test something I read about.

Apparently the New ternary operator does not allow for  (......Expression ) Then. in the IF and also as caused some non-Ternary IF statements to fails also
not allowing a (...) around the complete expression.

 I hope this mistake didn't make it here with the trunk.

Jamie
The only true wisdom is knowing you know nothing

LeP

  • Sr. Member
  • ****
  • Posts: 426
Re: Ternary operator in Delphi, Too early of a release?
« Reply #1 on: July 06, 2026, 11:31:20 pm »
I don't understand ...

Can you post a example of code ?
Un Sistema per domarli, un IDE per trovarli, un codice per ghermirli e nel framework incatenarli.
An operating system to tame them, an IDE to find them, a code to catch them and in the framework chain them.

jamie

  • Hero Member
  • *****
  • Posts: 7823
Re: Ternary operator in Delphi, Too early of a release?
« Reply #2 on: July 06, 2026, 11:34:15 pm »
 Result := If (Expression......) Then True_Value else FalseValue;

                  ^^^^^^^^^^^
(....)

Jamie
The only true wisdom is knowing you know nothing

LeP

  • Sr. Member
  • ****
  • Posts: 426
Re: Ternary operator in Delphi, Too early of a release?
« Reply #3 on: July 06, 2026, 11:39:54 pm »
Code: Pascal  [Select][+][-]
  1.   var Value := if (Application.IsRightToLeft) then 'Right to Left' else 'Left to Right';

or you think something like this:

Code: Pascal  [Select][+][-]
  1. var
  2.   Prova: 1..9;
  3.  
  4. begin
  5.   prova := 3;
  6.   var Value := if (prova in [2..3]) then 'Prova in range' else 'Prova not in range';
  7.   ShowMessage(Value);
  8. end;
« Last Edit: July 06, 2026, 11:49:24 pm by LeP »
Un Sistema per domarli, un IDE per trovarli, un codice per ghermirli e nel framework incatenarli.
An operating system to tame them, an IDE to find them, a code to catch them and in the framework chain them.

jamie

  • Hero Member
  • *****
  • Posts: 7823
Re: Ternary operator in Delphi, Too early of a release?
« Reply #4 on: July 07, 2026, 12:12:03 am »
Does not matter, When the ternary was put in it effected the normal IF operation.

If ( someExpression ) Then....

it causes unwanted effects now.

I don't know the exact version we have at work, its possible it has been fixed with a patch but I believe it was just release not to long ago and the Ternary operator was one of the features it claimed.

 I was reading some threads about someone finding out that placing the Expression within a closure (....) causes the compiler to generate bad code.

In any case, I play today at work and I am not sure if I could get it to fail but I wanted to see how the ternary operator works in Delphi now, from what I can see, It does not seem like its fully working correctly or I don't understand something.

I did a complex ternary operation and it looks like the compiler wasn't processing it correctly.

I tried something on the line of this

Code: Pascal  [Select][+][-]
  1. Value := If (Expression) Then If (Expression) else (Expression);
  2.  

Removing the "(..)" changed the behavior.

Like I said, I don't understand it fully I guess, its a good thing I didn't pay for the new Liecense  :o
The only true wisdom is knowing you know nothing

LeP

  • Sr. Member
  • ****
  • Posts: 426
Re: Ternary operator in Delphi, Too early of a release?
« Reply #5 on: July 07, 2026, 12:19:54 am »
Thisi is the right exp:

Code: Pascal  [Select][+][-]
  1.   var value := if ( .... ) then if ( .....) then 10 else 20 else 30;

I think to know what you read, but it is about other normal "if" not ternary (even if the post was talking about ternary).
« Last Edit: July 07, 2026, 12:24:51 am by LeP »
Un Sistema per domarli, un IDE per trovarli, un codice per ghermirli e nel framework incatenarli.
An operating system to tame them, an IDE to find them, a code to catch them and in the framework chain them.

 

TinyPortal © 2005-2018