首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

!编写一个集成多个控件的自定义组件出错,"Control '' has no parent window"

2013-04-07 
求助!编写一个集成多个控件的自定义组件出错,Control '' has no parent window将下面注释部分

求助!编写一个集成多个控件的自定义组件出错,"Control '' has no parent window"
将下面注释部分去掉注释,编译安装时没报错,但将控件拖到窗体时就会报错,提示:
"Control '' has no parent window"


unit QZYRichText;

interface

uses
  SysUtils, Classes, Controls, ExtCtrls, ComCtrls, Buttons;

type
  TQZYRichText = class(TPanel)
  private
    { Private declarations }
    TopPanel: TPanel;
    BottomPanel: TPanel;
    TextPanel: TRichEdit; // 文件编辑框
    LastSpeed: TSpeedButton;  // 撤消按钮
    CutSpeed: TSpeedButton; // 剪贴按钮
    CopySpeed: TSpeedButton; // 复制按钮
    PasteSpeed: TSpeedButton; // 粘贴按钮
  protected
    { Protected declarations }
  public
    { Public declarations }
    Constructor Create(AOwner: TComponent); Override;
    Destructor Destroy; Override;
  published
    { Published declarations }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('QZYRichText', [TQZYRichText]);
end;

Constructor TqzyRichText.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);;
  TopPanel := TPanel.Create(Self);
  BottomPanel := TPanel.Create(Self);
  TextPanel := TRichEdit.Create(Self);
  LastSpeed := TSpeedButton.Create(Self);
  CutSpeed := TSpeedButton.Create(Self);
  CopySpeed := TSpeedButton.Create(Self);
  PasteSpeed := TSpeedButton.Create(Self);

  TopPanel.Parent := Self;
  BottomPanel.Parent := Self;
  TextPanel.Parent := Self.BottomPanel;
  LastSpeed.Parent := Self.TopPanel;
  //CutSpeed.Parent := Self.TopPanel;
  //CopySpeed.Parent := Self.TopPanel;
  //PasteSpeed.Parent := Self.TopPanel;

//*******************************************
// 各控件初始大小
//*******************************************
  Self.Width := 400;
  Self.Height := 300;
  TopPanel.Height := 30;
  TextPanel.Width := 390;
  TextPanel.Height := 250;

//********************************************
// 各控件位置
//********************************************
  LastSpeed.Left := 5;
  LastSpeed.Top := 5;
  CutSpeed.Left := 33;
  CutSpeed.Top := 5;
  CopySpeed.Left := 66;
  CopySpeed.Top := 5;
  PasteSpeed.Left := 99;
  PasteSpeed.Top := 5;
  TextPanel.Left := 5;
  TextPanel.Top := 32;

  TopPanel.Align := alTop;
  BottomPanel.Align := alClient;
  TextPanel.Align := alClient;

  LastSpeed.Visible := True;
  CutSpeed.Visible := True;
  CopySpeed.Visible := True;


  PasteSpeed.Visible := True;
  TextPanel.Visible := True;

  TopPanel.BringToFront;
  BottomPanel.BringToFront;
  LastSpeed.BringToFront;
  CutSpeed.BringToFront;
  CopySpeed.BringToFront;
  PasteSpeed.BringToFront;
  TextPanel.BringToFront;
  Self.SendToBack;
end;

Destructor TqzyRichText.Destroy;
begin
   TextPanel.Free;
   inherited;
end;

end.



这里

  //CutSpeed.Parent := Self.TopPanel;
  //CopySpeed.Parent := Self.TopPanel;
  //PasteSpeed.Parent := Self.TopPanel;
delphi
[解决办法]
类接口声明部分加上
procedure SetParent(AParent: TWinControl); override;

实现部分加上
procedure TQZYRichText.SetParent(AParent: TWinControl);
begin
  //被注释掉的代码放在这里!
  CutSpeed.Parent := Self.TopPanel;
  CopySpeed.Parent := Self.TopPanel;
  PasteSpeed.Parent := Self.TopPanel;
end;
[解决办法]

    ......
    CopySpeed: TSpeedButton; // 复制按钮
    PasteSpeed: TSpeedButton; // 粘贴按钮
  protected
    { Protected declarations }
    procedure CreateParams(var Params: TCreateParams); override; 
   .....

procedure TQZYRichText.CreateParams(var Params: TCreateParams);
begin
  inherited;
  
  // 来这里玩嘛
end;

[解决办法]
引用:
引用:TopPanel.Parent := AOwner;
报错了 =.=
Incompatible types: 'TWinControl' and 'TComponent'

TopPanel.Parent := TWinControl(self.Owner);

热点排行