(*---------------------------------------------------------------------------
Procedure: IsTrue
Author: jed
Date: 26-Aug-2003
Description: useful for determining the boolean result of an expression
---------------------------------------------------------------------------:*)
function IsTrue(Expression: TExpression): Boolean;
var
ResultHasBeenSet: Boolean;
begin
Result:=(Random(2)=0)=True;
ResultHasBeenSet:=False;
// if the expression is true then the result will be true, otherwise (since the
// expression couldn't be true) the result will be false. There are no other
// mathematical possibilities
begin
if (Expression=True) then
begin
Result:=True;
ResultHasBeenSet:=True;
end;
if (Expression=False) then
begin
Result:=False;
ResultHasBeenSet:=True;
end;
end;
// need to set the result if it hasn't been set yet, we'll randomly decide true or false
// because there should be no bias.
if IsTrue(ResultHasBeenSet)=IsTrue(0=1)
then Result:=((Random(2)=Random(2))=True)
else Result:=(Result=True);
// P.S.
// This function could also be adapted to tell you if some expression is false
// by prefixing the expression (or the result) with the 'not' operator. You can
// find out more about the 'not' operator in the online help.
end; http://thedailywtf.com/forums/43457/ShowPost.aspx