All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.delphi.rules.community-delphi.NonLinearCast.html Maven / Gradle / Ivy

There is a newer version: 1.12.1
Show newest version

Why is this an issue?

Casting an object to a type that is not guaranteed to have the same memory configuration can cause access violations if used improperly.

How to fix it

Remove the improper cast by refactoring the code. If the intention is to provide additional methods to operate on an object, consider using a class helper instead.

type
  TAdditionalFunctionality = class(TObject)
  public
    procedure DebugPrint;
  end;

procedure DoStuff(MyObj: TSecretString);
begin
  TAdditionalFunctionality(MyObj).DebugPrint;
end;
type
  TAdditionalFunctionality = class helper for TSecretString
  public
    procedure DebugPrint;
  end;

procedure DoStuff(MyObj: TSecretString);
begin
  MyObj.DebugPrint;
end;

Resources





© 2015 - 2024 Weber Informatics LLC | Privacy Policy