Torsten Bonde Christiansen wrote 6 lines
Hi List.
Is it possible to jump a couple of levels in the inherited hierarchy when
calling "inherited" on a method?
Hmm, don't know whether you're the same person or not :), but I replied in a stackoverflow question the next day after it was asked (see here: http://stackoverflow.com/questions/4662744/delphi-how-to-call-inherited-inherited-ancestor/4670457#4670457) and it looked like the host didn't notice :). At least this variant seemed
to work
code is self-explanatory
type
TGrandParent = class(TObject)
public
procedure Show;virtual;
end;
TParent = class(TGrandParent)
public
procedure Show;override;
end;
THackParent = class(TGrandParent)
private
procedure CallInheritedShow;
end;
TMyObject = class(TParent)
public
procedure Show;override;
end;
{ TGrandParent }
procedure TGrandParent.Show;
begin
MessageDlg('I''m the grandparent', mtInformation, [mbOk], 0);
end;
{ TParent }
procedure TParent.Show;
begin
inherited;
MessageDlg('I''m the parent', mtInformation, [mbOk], 0);
end;
{ THackParent }
procedure THackParent.CallInheritedShow;
begin
inherited Show;
end;
{ TMyObject }
procedure TMyObject.Show;
begin
THackParent(Self).CallInheritedShow;
end;
procedure TForm6.Button6Click(Sender: TObject);
var
Obj: TMyObject;
begin
Obj:=TMyObject.Create;
try
Obj.Show;
finally
Obj.Free;
end;
end;
+
Max