org.sonar.l10n.delphi.rules.community-delphi.NilComparison.html Maven / Gradle / Ivy
Why is this an issue?
System.Assigned
is more flexible and has less edge cases than a normal nil
comparison. In particular:
Assigned
can be used to test if object procedures are assigned
-
Assigned
always checks the assignment of function references themselves -
nil comparisons may call the function and check the assignment of its return value
Assigned
is clearer and more self-documenting
How to fix it
Replace the nil comparison with a call to Assigned
:
procedure LogAssigned(MyObj: TObject);
begin
if MyObj <> nil then begin
Writeln('Object is assigned');
end;
end;
procedure LogAssigned(MyObj: TObject);
begin
if Assigned(MyObj) then begin
Writeln('Object is assigned');
end;
end;
Resources
© 2015 - 2024 Weber Informatics LLC | Privacy Policy