Inherited

The inherited operator can be used for the following expressions to explicitly operate on the implementation provided by the base class of the current Class, instead of a potential override in the current type.

When overriding a class Member, inherited is the only way to access the override functionality from the descendant type, as all direct calls to the member will be directed to the override version, as part Polymorphism.

When used standalone, the keyword will call the inherited version of the Method, Property or Constructor that exactly matches the current one in name and signature.

type
  Foo = class
  public
    constructor; 
    begin
    end;
  end;

  Bar = class(Foo)
  public
    constructor; 
    begin
      inherited; // calls the exact same (in this case name- and parameterless) constructor in the base
    end;
  end;

inherited can also be used with an explicit member name and (optional) parameters, to call the same or any member in the base class.

type
  Foo = class
  public
    method Test1; virtual;
    begin
    end;

    method Test2(aValue: String); virtual;
    begin
    end;
  end;

  Bar = class(Foo)
  public
    method Test1; virtual;
    begin
      inherited Test2('Hello, Unnamed'); // explictly calls Test2 of the base, not Bar.Test2
    end;

    method Test2(aValue: String); virtual;
    begin
      inherited Test2($'Hello, {aValue} 🖖'); // calls same method in base, but w/ different value;
    end;
  end;

Inherited in Constructors

While calling into the base is optional for regular methods or properties, Constructors must always call a a different constructor of the same class that (eventually) calls into a constructor in the base class.

Constructors without an explicit Constructor Call will automatically either call a constructor matching the same parameters (if available) or the parameterless constructor (again, if available) of the base class.

The Constructor Call and Constructors: Deferred Construction topics cover this in more detail.

See Also