#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2010
    Posts
    4
    Rep Power
    0

    Call Base Class Method


    How to access a base class method in Delphi?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,054
    Rep Power
    383
    Can you give us the context in which you need this?
    What do you mean by "base class"?
    Technically the base class for everything is TObject and I am sure you do not mean that.
    It also depends on how the method is declared and whether you are talking about
    calling it from within a descendent or from another object or unit.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    151
    Rep Power
    2
    Use keyword inherited before the name of the method of the parent class you want to call. For example:

    Code:
    procedure TChild1.PrintText(const AText: string);
    begin
      inherited PrintText(AText);
      ...
      ...
    end;

    Actually if the parent method have the same name and the same parameters with the one where the descendant would call it (like in the example above). You can get away with only inherited. Like this:

    Code:
    procedure TChild1.PrintText(const AText: string);
    begin
      inherited;
      ...
      ...
    end;

IMN logo majestic logo threadwatch logo seochat tools logo