如果不让父类的属性出现在属性编辑器中?
TLine = class(TGraphicControl)
父类中有height、width等属性,我不想让这些属性显示在我新组件的属性编辑器中,怎么实现?
因为我已经通过其他属性控制了height和width属性,就不想让这些出现在编辑器中。
谢谢先!
[解决办法]
如果从TComponent继承,那很多代码都要自己去写,那岂不累死。
因为只读属性是不会出现在属性编辑器中的,所以你把height、width属性重设为只读,以TButton为例:
unit MyButton;
interface
uses
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;
implementation
procedure 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.
[解决办法]
这样TMyButton控件的Height属性就不会出现在属性编辑器中了,但是如果因为Height是只读属性,所以你必须用Public的方法SetHeight来设置Height属性。