Implementing Immediate If (IIF) in Delphi

, \t\t , I have never regretted moving from C++ to Object Pascal, but I did,, miss a useful feature of C - the Immediate If (iif).,,,It seems like a great deal of my code involves simple if statements,, such as -,,,, if LambCount = 1 then,, begin,, AString := 'a';,, LambString := 'lamb';,, end else,, begin,, AString := '';,, LambString := 'lambs';,, end;,,, FullString := 'Mary had ' + AString + ' little ' + LambString;,,, The introduction of method overloading in Delphi 4 enabled me to,, create my own verison of iif in Object Pascal.,,, The following code is part of standard utility unit I include in all,, my projects:,,, {begin listing},,, unit StandardUtils;,,, grænseflade,,, funktion, hvis (betingelse: boolean,,, truestring: string,,, falsestring: string = "): string, overbelastning,,, funktion, hvis (betingelse: boolean,,,,,,, trueint: heltal,, falseint: heltal = 0): heltal overbelastning,,,, gennemførelse,,, (********************************************************************}, funktion, hvis (betingelse: boolean,,, truestring: string,,, falsestring: string ="): string, overbelastning, begynder, hvis tilstand så, resultat: = truestring,,,, resultat: = falsestring,,,,,,,,,, (********************************************************************}, funktion, hvis (betingelse: boolean,,,rueint: heltal,, falseint: heltal = 0): heltal overbelastning, begynder, hvis tilstand så, resultat: = trueint,,,, resultat: = falseint,,,,,,, (********************************************************************},,.,,, {ende optagelse),



Previous:
Next Page: