IsHandled should never be set to false #715
Closed
christophstuber
started this conversation in
New Rule
Replies: 2 comments 1 reply
-
this only applies if ishandled is a parameter, not a variable. procedure AnyThing()
var
IsHandled: Boolean;
begin
OnDoSomething(IsHandled);
if IsHandled then
exit;
IsHandled := false; // <-- should not raise a warning
OnDoAnotherThing(IsHandled)
if IsHandled then
exit;
...
end; |
Beta Was this translation helpful? Give feedback.
1 reply
-
Our current development pattern is to
So, below pattern is currently used in lots of places and looks good to us (although hard to include this case in the rule I guess)
or
If above case can't be supported, we will be forced to refactor to below code instead
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The IsHandled parameter should never be set to false, neither directly nor as the result of a condition evaluation or function call.
Setting IsHandled to false can cause issues, when an earlier subscriber set it to true.
This is fine:
IsHandled := true;
This is also fine:
This is obviously bad:
IsHandled := false;
This is also very dangerous:
So is this:
IsHandled := MyCondition;
Beta Was this translation helpful? Give feedback.
All reactions