Solved

Inherited x 2

Posted on 2002-06-27
6
161 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 134 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
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!

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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