[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 166
  • Last Modified:

Inherited x 2

I'm well aware of how to call an overridden ancestor's method in the descendent class' implementation: Simply use the "inherited" keyword which will send the same parameters in the same order to the inherited ancestor method.

However, I have a situation where it would be best for a descendent class NOT to call the inherited method of its IMMEDIATE ancestor, but the method that was defined TWO classes ago!  How do I do this?
0
Pummel
Asked:
Pummel
1 Solution
 
TOndrejCommented:
It's neither possible (without nasty hacks with VMT) nor really needed.
If you have such situation it usually means you need to redesign your class hierarchy.

Perhaps an acceptable quick workaround might be to implement the immediate ancestor's method to call the next ancestor's method based on a parameter or perhaps a property flag.
0
 
bes67Commented:
Try something like this:

Suppose you have following class hierarchy

type
  TSFn = function:Boolean of object;

  TGrandClass = class
  public
    function SomeFunction: Boolean; virtual;
  end;

  TBaseClass = class(TGrandClass)
  public
    function SomeFunction: Boolean; override;
  end;

  TSomeClass = class(TBaseClass)
  public
    function SomeFunction: Boolean; override;
  end;

and you want to call TGrandClass.SomeFunction from TSomeClass.SomeFunction without calling TBaseClassFunction. Well, here it is

function TSomeClass.SomeFunction: Boolean;
var gcq: TMethod;
begin
  gcq.Code := @TGrandClass.SomeFunction;
  gcq.Data := Self;
  Result := TSFn(gcq);
end;

0
 
Lee_NoverCommented:
interesting :)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
kretzschmarCommented:
? what is tsfn()
0
 
Lee_NoverCommented:
type
 TSFn = function:Boolean of object;


so in the case above it's a cast :)
0
 
kretzschmarCommented:
oops, overread this declaration,
thanks lee for pointing out

meikl ;-)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now