Delphi Error – H2219 Private symbol ‘%s’ declared but never used

Delphi Compiler Error

H2219 Private symbol ‘%s’ declared but never used

Reason for the Error & Solution

The symbol referenced appears in a private section of a class, but is never used by the class. It would be more memory efficient if you removed the unused private field from your class definition.

program Produce;
  type
    Base = class
    private
      FVar : Integer;
      procedure Init;
    end;

procedure Base.Init;
begin
end;

begin
end.

Here we have declared a private variable which is never used. The message will be emitted for this case.

program Solve;
program Produce;
  type
    Base = class
    private
      FVar : Integer;
      procedure Init;
    end;

procedure Base.Init;
begin
  FVar := 0;
end;

begin
end.

There are various solutions to this problem, and since this message is not an error message, all are correct. If you have included the private field for some future use, it would be valid to ignore the message. Or, if the variable is truly superfluous, it can be safely removed. Finally, it might have been a programming oversight not to use the variable at all; in this case, simply add the code you forgot to implement.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...