Quantcast
Channel: Delphi – The Wiert Corner – irregular stream of stuff
Viewing all articles
Browse latest Browse all 1445

inheritance – Delphi: How to call inherited inherited ancestor? – Stack Overflow

$
0
0

Officially, the answer to [WayBack] inheritance – Delphi: How to call inherited inherited ancestor? – Stack Overflow is that you can’t on the language level as I explained in my answer

You can’t in a regular language way, as this would break the object oriented aspects of the language.

You can fiddle around with pointers and clever casts to do this, but before even starting to answer that: is this really what you want?

As others mentioned: your need sounds like a serious “design smell” (which is similar to code smell, but more severe.

Edit:

Going down the pointer fiddling road might save you work in the short term, and cost you weeks of work in the long term.
This makes for some good reading on that: Upstream decisions, downstream costs.

If you really want, then there is a clever hack around this by [WayBack] User kludg – Stack Overflow.

His hack is centered around understaning what what the [WayBack] System.TMethod Record essentially is:

TMethod = record
  Code: Pointer;
  Data: Pointer;
end;

The TMethod stores the Code and Data pointers for a method. This type can be used in a type cast of a method pointer to access the code and data parts of the method pointer.

You can also furnish a TMethod variable by assigning Data a pointer to an object, and assigning Code using MethodAddress, specifying the method name as a string parameter to that method.

So if you have a Method variable of the procedure of object type, then you can set the Code part to reference the ancestor method, and the Data part to Self and call the correct method.

It is important to resalise that this still is a hack, which hides the “design smell” you are trying to solve.

W warming is in place:

Even after applying the hack, your design still smells, and will likely continue to rotten further until a moment some essential flesh in your design and the bones of your design start to collapse.

–jeroen


Viewing all articles
Browse latest Browse all 1445

Trending Articles