RAD Studio (Common)
ContentsIndex
PreviousUpNext
W1010: Method '%s' hides virtual method of base type '%s' (Delphi)

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
      procedure VirtuMethod; virtual;
      procedure VirtuMethod2; virtual;
    end;

    Derived = class (Base)
      procedure VirtuMethod;
      procedure VirtuMethod2;
    end;

  procedure Base.VirtuMethod;
  begin
  end;

  procedure Base.VirtuMethod2;
  begin
  end;

  procedure Derived.VirtuMethod;
  begin
  end;

  procedure Derived.VirtuMethod2;
  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.

program Solve;

  type
    Base = class
      procedure VirtuMethod; virtual;
      procedure VirtuMethod2; virtual;
    end;

    Derived = class (Base)
      procedure VirtuMethod; override;
      procedure Virtu2Method;
    end;

  procedure Base.VirtuMethod;
  begin
  end;

  procedure Base.VirtuMethod2;
  begin
  end;

  procedure Derived.VirtuMethod;
  begin
  end;

  procedure Derived.Virtu2Method;
  begin
  end;

begin
end.

There are three alternatives to take when solving this warning. 

First, you could specify override to make the derived class' procedure also virtual, and thus allowing inherited calls to still reference the original procedure. 

Secondly, you could change the name of the procedure as it is declared in the derived class. Both methods are exhibited in this example. 

Finally, you could add the reintroduce directive to the procedure declaration to cause the warning to be silenced for that particular method.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!