So, the question mow is : "Ifthen" is useful for what ?
I use it quite often because of the compactness.
Color := IfThen(c > 0, red, green);
versus
if c > 0 then Color := red else Color := green;
Of course it is not useable in the cases in which there is something that must be evaluated as input and can raise exceptions.
Also, IMO, when using it one should consider that, even if the evaluations necessary to the IfThen input do not raise exceptions like in the case presented here, it is still necessary to keep in mind that the evaluations have a computational cost and this cost could be also extremely high. So doing it
always has an impact on the overall program efficiency.
See this example:
program ifthentest;
{$mode delphi}
uses
Classes, SysUtils;
function A1(): Integer;
begin
Sleep(2000); // Simulates limited number crunching
Result := 1;
end;
function A2(): Integer;
begin
Sleep(10000); // Simulates big number crunching
Result := 2;
end;
var
r: Integer;
begin
r := IfThen<Integer>(False, A1(), A2());
//if False then
// r := A1()
//else
// r := A2();
end.
It always take 12000 msec to complete even if you put True. While the commented part takes 2000 or 10000 depending on condition.