[fpc-pascal] Skipping an the "inherited" of an ancestor
    Max Vlasov 
    max.vlasov at gmail.com
       
    Fri Jan 14 23:05:04 CET 2011
    
    
  
On Fri, Jan 14, 2011 at 10:38 PM, Torsten Bonde Christiansen
<tc at epidata.dk>wrote:
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20110115/d94ba36c/attachment.html>
    
    
More information about the fpc-pascal
mailing list