I have a function which is evaluate multiple (7, in my case) boolean variables and conditions and the result is true if only one of them true (and the rest false of course). I have the following code:
function GetExclusiveTrue: boolean;
begin
Result:= (
Integer(BoolVar1) +
Integer(BoolVar2) +
Integer(BoolFunc3) +
Integer(BoolVar4) +
Integer(BoolFunc5) +
Integer(BoolVar6) +
Integer(BoolVar7)) = 1;
end;
I'm just wondering if there is any better solution than this?
PS: I think I haven't defined properly what is my problem.
I'm looking for a solution using logical operators only, without any casting involved.
PS2: Look like I can't explain properly what I'm looking for. I want to see a solution without iteration, selection, function calls, etc. ONLY boolean operators allowed. Why? I just want to know if that is possible or not. Looking for a combination of logical operations which provides the same result as the function above.