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 E2313 Attribute – Known attribute cannot specify properties Reason for the Error & Solution No further information...
Delphi Compiler Error E2379 Virtual methods not allowed in record types Reason for the Error & Solution No further information...
Rodrigo , one of the long time Delphi Developer has been working on one of his personal project “Delphi IDE...