Delphi Error – W1010 Method ‘%s’ hides virtual method of base type ‘%s’

Delphi Compiler Error

W1010 Method ‘%s’ hides virtual method of base type ‘%s’

Reason for the Error & Solution

You have declared a method which has the same name as a virtual method in the base class. Your new method is not a virtual method; it will hide access to the base’s method of the same name.

program Produce;

type
  Base = class(TObject)
    procedure VirtuMethod; virtual;
    procedure VirtuMethod2; virtual;
    procedure VirtuMethod3; virtual;
  end;

  Derived = class(Base)
    procedure VirtuMethod;
    procedure VirtuMethod2;
    procedure VirtuMethod3;
  end;
 
procedure Base.VirtuMethod;
begin

end;
 
procedure Base.VirtuMethod2;
begin

end;

procedure Base.VirtuMethod3;
begin

end;

procedure Derived.VirtuMethod;
begin

end;
 
procedure Derived.VirtuMethod2;
begin

end;

procedure Derived.VirtuMethod3;
begin

end;

begin

end.

Both methods declared in the definition of Derived will hide the virtual functions of the same name declared in the Base class.

There are three alternatives to take when solving this warning.

  1. You could specify override to make the derived class’ procedure also virtual, if the ancestor’s respective method is declared as virtual or dynamic, and thus allowing inherited calls to still reference the original procedure.
  2. You could change the name of the procedure as it is declared in the derived class.
    Both of these methods are exhibited in the source code snippets above.
  3. You could add the reintroduce directive to the procedure declaration to cause the warning to be silenced for that particular method. The reintroduce keyword instructs the Delphi compiler to hide the respective method and suppress the warning, because it is unlikely to override a method of the same name from a base class that is not virtual or dynamic.

program Solve;
 
type
  Base = class(TObject)
    procedure VirtuMethod; virtual;
    procedure VirtuMethod2; virtual;
    procedure VirtuMethod3; virtual;
  end;
 
  Derived = class(Base)
    procedure VirtuMethod; override;
    procedure Virtu2Method;
    procedure VirtuMethod3; reintroduce;
  end;
 
procedure Base.VirtuMethod;
begin

end;
 
procedure Base.VirtuMethod2;
begin

end;

procedure Base.VirtuMethod3;
begin

end;
 
procedure Derived.VirtuMethod;
begin

end;
 
procedure Derived.Virtu2Method;
begin

end;

procedure Derived.VirtuMethod3;
begin

end;
 
begin

end.

See Also

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...