Skip to content

BSL266 — Using parameter "Cancel"

Summary

Using parameter "Cancel"

Identifiers

Field Value
Rule code BSL266
Compatible alias UsingCancelParameter
Severity WARNING
Enabled by default Yes
Implemented Yes
Tags correctness, events

Behavior

  • The public identifier BSL266 and alias UsingCancelParameter are stable.
  • The rule reports the cases documented on this page.
  • Suppressions and project configuration are applied before publication.
  • The rule requires neither an external analyzer nor network access.

Configuration and suppression

BSL### is the primary stable identifier. The compatible alias is accepted in select, ignore, and compatible block suppression comments.

[tool.onec-hbk-bsl]
select = ["BSL266"]
ignore = ["UsingCancelParameter"]

All three suppression families support both a current line and a range. When an opening comment follows code, it affects only that line. Use any one form:

  • noqa:
Value = "example";  // noqa: BSL266
  • bsl-disable:
Value = "example";  // bsl-disable: BSL266
  • compatible BSLLS form:
Value = "example";  // BSLLS:UsingCancelParameter-off

When the same opening comment is on a line by itself, it starts a range. Close it with the matching marker from the same family:

// noqa: BSL266
// code without this diagnostic
// noqa-enable: BSL266

// bsl-disable: BSL266
// code without this diagnostic
// bsl-enable: BSL266

// BSLLS:UsingCancelParameter-off
// code without this diagnostic
// BSLLS:UsingCancelParameter-on

To disable the rule until the end of the file, omit the closing noqa-enable, bsl-enable, or BSLLS:…-on marker.

Opening and closing markers must belong to the same family.

Description

In event handlers of object's modules, record sets, forms and etc. using parameter "Cancel" (for example BeforeWrite and etc.) it should not be assigned value "false". This is due to the fact, that in code of event handlers the parameter "Cancel" can be set in several consecutive checks (or in several subscriptions on the same event). In this case, by the time the next check is performed, the Cancel parameter may already contain the True value, and you can erroneously reset it back to False. In addition, with configuration improvements, the number of these checks may increase.

Examples

Incorrect

Procedure BeforeWrite(Cancel)
  ...
  Cancel = CheckName();
  ...
EndProcedure

Correct

Procedure BeforeWrite(Cancel)
  ...
  If CheckName() Then
   Cancel = True;
  EndIf;
  ...
EndProcedure

or

Cancel = Cancel or CheckName();

Sources