子类:TGraphicControl
如何在TGraphicControl Create的时候创建一个父类TWinControl来包容自己?这个代码如何写?TXGraphic=class(TGraphicControl)
......................
TXGraphicBox=class(WinControl)
......................
constructor TGraphic.Create(AOwner: TComponent);
begin
??????????????
  inherited Create(AOwner);
??????????????
end;在此先谢过!

解决方案 »

  1.   

    楼主,这样的思路合逻辑吗??
    不过,非要这样的话,也不是不行吧??我没有试,给出个思路你试试吧
    TXGraphic=class(TGraphicControl)
    ......................
    TXGraphicBox=class(WinControl)
    ......................
    constructor TXGraphic.Create(AOwner: TComponent);
    begin
    ??????????????
      inherited Create(AOwner);
      TXGraphicBox.Create(Self);
      TXGraphicBox.Parent:= XXX;
      Self.Parent:= TXGraphicbox;
    ??????????????
    end;
      

  2.   

    constructor TXGraphic.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      TXGraphicBox.Create(AOwner);
      TXGraphicBox.Parent:= AOwner;
      Self.Parent:= TXGraphicbox;
    end;
      

  3.   

    我是这样做的:
    constructor TXGraphic.Create(AOwner: TComponent);
    begin
      TXGraphicBox.Create(AOwner);
      TXGraphicBox.Parent:=TForm(AOwner);
      inherited Create(AOwner);
      Self.Parent:= TXGraphicbox;
    end;显示出来的两个控件分开独立,没有成功。
      

  4.   

    constructor TXGraphic.Create(AOwner: TComponent);
    var
      XGraphicbox : TXGraphicbox;
    begin
      XGraphicbox := TXGraphicBox.Create(AOwner);
      XGraphicBox.Parent:=TForm(AOwner);
      inherited Create(AOwner);
      Self.Parent:= XGraphicbox;
    end;
      

  5.   

    结贴通过:
    constructor TXGraphic.Create(AOwner: TComponent);
    begin
      TXGraphicBox.Create(AOwner);
      TXGraphicBox.Parent:=TForm(AOwner);
      inherited Create(AOwner);
      Self.Parent:= TXGraphicbox;
    end;
    前面没有成功是因为创建TXGraphic的时候给为它指定父类为TForm.取消外部指定父类该为内部指定父类就成功了。纯属操作失误:)谢谢两位!