delphi封装了windows的消息循环,delphi的所有组件都继承自TObject类
inherited是使当前组件不处理的一些消息,向类继承层次中的上一级传递,并最终实现消息被父类默认处理。

解决方案 »

  1.   

    有inherited就是先继承父类的方法,然后再执行自己的方法
    没有就是没有继承罗
      

  2.   

    仔细看一下联机帮助:The reserved word inherited plays a special role in implementing polymorphic behavior. It can occur in method definitions, with or without an identifier after it.
    If inherited is followed by the name of a member, it represents a normal method call or reference to a property or field梕xcept that the search for the referenced member begins with the immediate ancestor of the enclosing method抯 class. For example, wheninherited Create(...);occurs in the definition of a method, it calls the inherited Create.
    When inherited has no identifier after it, it refers to the inherited method with the same name as the enclosing method. In this case, inherited takes no explicit parameters, but passes to the inherited method the same parameters with which the enclosing method was called. For example,inherited;occurs frequently in the implementation of constructors. It calls the inherited constructor with the same parameters that were passed to the descendant.
    inherited的作用是调用父类的成员函数,不加函数名是调用父类中同名的方法。
      

  3.   

    看看这个例子,对理解有帮助:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
      THuman=class //基类
      public
         procedure showinfo1;virtual;
         procedure showinfo2;virtual;
      end;
      TStudent=class(Thuman) //派生类
      public
         procedure showinfo1;override;// 虚拟继承
         procedure showinfo2;override;
      end;
      TWorker=Class(THuman) //派生类
      public
         procedure showinfo1;override;
         procedure showinfo2;override;
      end;
    var
      Form1: TForm1;implementation{$R *.dfm}
    procedure THuman.showinfo1 ;
    begin
       ShowMessage('THuman Showinfo1');
    end;
    procedure THuman.showinfo2 ;
    begin
       ShowMessage('THuman Showinfo2');
    end;
    procedure TStudent.showinfo1 ;
    begin
       ShowMessage('TStudent Showinfo1');
       inherited showinfo2; //调用父类中不同名的成员函数
    end;
    procedure TStudent.showinfo2 ;
    begin
       ShowMessage('TStudent Showinfo2');
    end;
    procedure TWorker.showinfo1 ;
    begin
       ShowMessage('TWorker Showinfo1');
      inherited; //调用父类中的同名函数
    end;
    procedure TWorker.showinfo2 ;
    begin
       ShowMessage('TWorker Showinfo2');
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    var
       H:THuman;
    begin
       H:=THuman.Create ;
       h.showinfo1;
       h.showinfo2;
    end;procedure TForm1.Button2Click(Sender: TObject);
    var
       S:TStudent;
    begin
       s:=TStudent.Create ;
       s.showinfo1 ;
       s.showinfo2;
    end;procedure TForm1.Button3Click(Sender: TObject);
    var
       W:TWorker;
    begin
       w:=Tworker.Create ;
       w.showinfo1 ;
       w.showinfo2;
    end;end.