Forum > General

Inline If statement, i.e. IIF()?

(1/5) > >>

Does Lazarus/FPC have an inline IIF()? It seems like long time ago back in the 1980's with Turbo Pascal or in the early 1990's in Delphi 5 or 7 there was an IIF().  I maybe mistaken.

I tried to find it in Help but came of with no search.

the closes I can think of is the "ifThen" function.

IIF is a $M access thing and not sure if that actually existing, I've never seen it here.

There are procedural workarounds ifthen() in delphi and FPC, but it evaluates all arguments(contrary to C\s "?"operator)

It might be that for some variants (e.g. strings ) you might need to include certain units (strutils in that case on at least Delphi)

Although I don't do a lot of database stuff, here is something that may interest  you.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Function IIF(A:array of Boolean;aIsTrue,aIsFalse:Variant):Variant;Var  I:Integer;  B:Boolean;Begin  B:= False;  For I := 0 To Length(A)-1 do   Begin    B :=A[I];    IF B=False then    Break;   end;Case B of True:Result := aIsTrue; False:Result:= aIsFalse;end;End;procedure TForm1.Button1Click(Sender: TObject);begin caption := IIf([1 =1,5=54, 7=7],'True','False')end;                                                 
With that, you should be able to return any  basic type since Variants are in use here.

also, you can test a series of conditions that need all to be true, not just one.


[0] Message Index

[#] Next page

Go to full version