Solved

Inherited x 2

Posted on 2002-06-27
6
157 Views
Last Modified: 2013-11-23
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
Comment
Question by:Pummel
6 Comments
 
LVL 8

Expert Comment

by:TOndrej
Comment Utility
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
 
LVL 1

Accepted Solution

by:
bes67 earned 134 total points
Comment Utility
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
 
LVL 12

Expert Comment

by:Lee_Nover
Comment Utility
interesting :)
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
? what is tsfn()
0
 
LVL 12

Expert Comment

by:Lee_Nover
Comment Utility
type
 TSFn = function:Boolean of object;


so in the case above it's a cast :)
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
oops, overread this declaration,
thanks lee for pointing out

meikl ;-)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now