?
Solved

Inherited x 2

Posted on 2002-06-27
6
Medium Priority
?
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 8

Expert Comment

by:TOndrej
ID: 7114821
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 536 total points
ID: 7115599
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
ID: 7116171
interesting :)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 7118524
? what is tsfn()
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7119382
type
 TSFn = function:Boolean of object;


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

Expert Comment

by:kretzschmar
ID: 7119670
oops, overread this declaration,
thanks lee for pointing out

meikl ;-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

770 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