R
R
Rainex2014-12-24 14:32:13
Delphi
Rainex, 2014-12-24 14:32:13

How to call an ancestor method in an ancestor method?

There is an abstract class TBase, the class TList is inherited from it. And from TList one more class Т2List is inherited. And here is the question of how to call a method from a TList class method, provided that the methods are overridden in the second class. inherited allows you to call the ancestor method, but if the ancestor method has functions that are defined in the current class, then they are executed, and I need the ancestor to be called

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
M_PRO, 2014-12-28
@M_PRO

As far as I understand there is:

TMyObject = class(TObject)
  procedure DoA; virtual;
  procedure DoB; virtual;
end;

TMyObject2 = class(TMyObject)
  procedure DoA; override;
  procedure DoB; override;
end;

...

TMyObject.DoA;
begin
   DoB;
end;

TMyObject.DoB;
begin
  WrtieLn('MyObject');
end;

TMyObject2.DoA;
begin
   inherited DoA; // fix
end;

TMyObject2.DoB;
begin
  WriteLn('MyObject2');
end;

And you expect to get the result of calling the DoA method of the TMyObject2 class, fixing the line marked fix with
the line MyObject in the console, the line MyObject instead of MyObject2.
Answer: it's not possible.
Solution:
1. If the classes are written by you, think about the design.
2. If the classes are not written by you, think about how to use them. It is possible to "patch" the source if it's completely screwed up. In this case, much more detailed information is needed.

V
Vadim, 2014-12-25
@kylt_lichnosti

Try to rephrase the question. And before that, a little understanding of the terminology.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question