如题,谢谢.解决立即可分

解决方案 »

  1.   

    不能隐藏
    根据Delphi类的继承规则,子类从父类继承的属性的可见性只能保持或者变大
    比如   (下面代码从VCL中Copy来的)
    TControl = class(TComponent)
      published
        property Width: Integer read FWidth write SetWidth;
        property Height: Integer read FHeight write SetHeight;
    TGraphicControl = class(TControl)
    TImage = class(TGraphicControl)
    那么从TControl 继承的所有东东都自动包含属性Width 和Height,并且可见范围是  published,你不能改变它,因为已经是最大的可见范围
    对外部可见范围(小->大)
    private<protected<public<=published
    ----------------
    unit Unit2;interface
    uses dialogs;
    type
      TBase=class(TObject)
      private
        FAge: integer;
        procedure SetAge(const Value: integer);
      protected
        property Age:integer read FAge write SetAge;
      end;  TFirst=class(TBase)
      public
        property Age ;
      end;
      // 你可发现TSecond 与TFirst的区别只在于public ,published  关键字
      //对于控件(就是设计期可以放到Form上面类)二者是不同的,
      //TSecond中Age可以通过属性编辑器 ,进行设计期 设置,
      //并可看见结果 ,另外还RTTI信息;而TFirst不能,
      TSecond=class(TBase)
      published
        property Age ;
      end;  TThird=class(TFirst)
      //即使你重新声明,缩小范围,但是其可见范围还是public  (父类的)
      private
        property Age ;          //一般不会这样用
      protected
        function s:integer;
      end;
    implementation{ TBase }procedure TBase.SetAge(const Value: integer);
    begin
      FAge:=Value;
      dialogs.ShowMessage('base property');
    end;{ TThird }function TThird.s: integer;
    begin
      Result:=Age;
    end;end.