TLine = class(TGraphicControl)父类中有height、width等属性,我不想让这些属性显示在我新组件的属性编辑器中,怎么实现?因为我已经通过其他属性控制了height和width属性,就不想让这些出现在编辑器中。谢谢先!

解决方案 »

  1.   

    TGraphicControl公开Left,Width等属性是因为IDE需要这些属性以使得你的组件可以放到From上用鼠标托托拉拉。如果你不打算把你的组件以可视化的方式工作那么就从TComponent派生吧。
      

  2.   

    如果从TComponent继承,那很多代码都要自己去写,那岂不累死。
    因为只读属性是不会出现在属性编辑器中的,所以你把height、width属性重设为只读,以TButton为例:
    unit MyButton;interfaceuses
      Classes, Controls, StdCtrls;type
      TMyButton = class(TButton)
      private
        function GetHeight: Integer;
      public
        procedure SetHeight(const Value: Integer);
      published
        property Height: Integer read GetHeight;
      end;  procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('test', [TMyButton]);
    end;function TMyButton.GetHeight: Integer;
    begin
      Result := TButton(Self).Height;
    end;procedure TMyButton.SetHeight(const Value: Integer);
    begin
      TButton(Self).Height := Value;
    end;end.
      

  3.   

    这样TMyButton控件的Height属性就不会出现在属性编辑器中了,但是如果因为Height是只读属性,所以你必须用Public的方法SetHeight来设置Height属性。
      

  4.   

    to dctony() ,按照你的方法,当我把控件放到窗体上时候,就出现stack overlow的提示,还让我关闭工程,重新启动delphi