如題!

解决方案 »

  1.   

    执行到inherited这一行的时候,自动执行父类的相关代码,执行完后再回来执行子类的
      

  2.   

    继承父类,执行父类代码。
    如果inherited 
    写在一些代码前边,先执行父类,再执行你写的代码,
    放后边则相反。
      

  3.   

    子类复写父类同名方法时,Inherited;   可以在子类此方法中保留父类同名方法的动作;如父类方法showinfo中有一个ShowMessage('Is   Father');   则在子类中复写此方法时,若加Inherited;,则其执行时到Inherited;处时会跳出'Is   Father'框,即进入了父类同名方法,执行完再回来接着执行子类方法中动作;若不用Inherited;,那么就不会跳出'Is   Father'框而只会执行子类方法中动作。说的多态在此表现更强,即代码复用功能,一个Inherited;就继承的父类同名方法的所有动作,子类复写再加强其功能即可
      

  4.   

    eg:
    constructor TMMM:Create(AOwner: TComponment);
    begin
    //调用父类的Create方法,创建此类。
    inherited; 
    //设置本实例的属性
    self.width := 20;
    self.Height := 80;//本实例中对象变量创建
    Lab :=TLabel.Create(self);
    Lab.Width := 20;
    Lab.Height := 19;end;destructor TMMM:Destroy();
    begin
    //本实例中对象变量释放
    FreeAndNil(Lab);
    //调用父类的Destroy方法,释放此实例。
    inherited; end;
      

  5.   

    楼主参考下 我发的帖子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--except that the search for the referenced member begins with the immediate ancestor of the enclosing method's class. For example, when inherited 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 or, if the enclosing method is a message handler, to the inherited message handler for the same message. 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后面followed一个成员名时,表示一个函数调用或一个属性的引用,比较特殊的是:如果inherited后followed一个其直接父类封装的方法,则它会先搜索父类相关方法执行
    Inherited后面如果直接跟当前类的方法名时,表示对这个方法的正常调用(貌似不用Inherited关键字也可以啊),如果Inherited后面跟的方法名不属于当前正在定义的类(不直接属于),则从当前类的直接父类开始搜索该方法(搜索父类方法),然后执行.
    补充:如果Inherited后门什么也不跟,则表示调用父类中跟当前方法同名的方法(参数也相同). 现在问题又来了:如果父类中该同名方法有好几个(因为重载),那么Inherited后面未加指示(identifier),那调用的是众多重载方法中的哪个呢? 与当前方法参数相同的那个么?如果当前方法也是一个重载方法呢(即参数与父类中的同名方法参数都不同)? 个人认为还是,在Inherited后面乖乖的加上具体的方法名和参数吧,偷这点懒,导致一大堆问题,不值得. 
      

  6.   

    帖子地址http://topic.csdn.net/u/20090702/10/d908e6b8-b8d1-4be6-b792-1c540d33a5f5.html