Evaluate multiple Boolean conditions separately, only one can be true (Delphi)

I have a function that evaluates multiple (7 in my case) Boolean variables and conditions, if only one of them is true, the result is true (of course the rest are false ). 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 just want to know if there is a better solution than this?

PS: I don’t think I correctly defined what my problem is.

I am looking for a solution that uses only logical operators and does not involve any conversion.

< p>PS2: It seems that I cannot explain correctly what I am looking for. I would like to see solutions without iteration, selection, function calls, etc. Only Boolean operators are allowed. Why? I just want to know if this is possible. Look for a combination of logical operations that provides the same results as the above functions.

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.

You want to use only logic and/or xor and not operators to implement this function. This is like this:

< p>

Result :=
(b1 and not (b2 or b3 or b4))
or (b2 and not (b1 or b3 or b4))
or (b3 and not (b1 or b2 or b4))
or (b4 and not (b1 or b2 or b3));

I gave an example with only four Boolean values, But the concept of any number is the same.

I have a function that evaluates multiple (7 in my case) boolean variables and conditions, if only If one of them is true, the result is true (of course the rest are false). 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 just want to know if there is a better solution than this?

PS: I don’t think I correctly defined what my problem is.

I am looking for a solution that uses only logical operators and does not involve any conversion.

< p>PS2: It seems that I cannot explain correctly what I am looking for. I would like to see solutions without iteration, selection, function calls, etc. Only Boolean operators are allowed. Why? I just want to know if this is possible. Look for a combination of logical operations that provides the same results as the above functions.

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.< /p>

You want to use only logic and/or xor and not operators to implement this function. This is like this:

Result := 
(b1 and not (b2 or b3 or b4))
or (b2 and not (b1 or b3 or b4))
or (b3 and not (b1 or b2 or b4))
or (b4 and not (b1 or b2 or b3));

I gave an example with only four Boolean values, but the concept of any number is the same.

p>

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3179 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.