我定义了一个继承与TPanel的控件,为什么在重载的Create里修改一些如Caption、Width等属性不起作用?
  TMyPanel = class(TPanel)
  ……
  public
    constructor Create(AOwner: TComponent); override;
  ……
  end;
……
constructor TDockPanel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Caption:='';//这句在设计时和运行时都无效果
  Width:=10;//这句只是在设计时起作用,运行时无效果
end;

解决方案 »

  1.   

    procedure TControl.SetName(const Value: TComponentName);
    var
      ChangeText: Boolean;
    begin
      ChangeText := (csSetCaption in ControlStyle) and
        not (csLoading in ComponentState) and (Name = Text) and
        ((Owner = nil) or not (Owner is TControl) or
        not (csLoading in TControl(Owner).ComponentState));
      inherited SetName(Value);
      if ChangeText then Text := Value;
    end;
    这些代码可以帮您明白
      

  2.   

    这只能说明单单继承CREATE是不行的。去看下TPANEL的源文件里关于CAPTION的有关操作都有那些,然后再决定重载那些部分。
      

  3.   

    TDockPanel和TMyPanel不是同一个类呀!
      

  4.   

    constructor TDockPanel.Create(AOwner: TComponent);改为constructor TMyPanel.Create(AOwner: TComponent);