我想创建一个继承了TShape类的TMyShape,使其一次创建两个连在一起的控件,下面是代码,添加到窗体时,已经创建了我想要的两个控件,
但是为什么显示不出来呢?constructor TMyShape.Create(AOwner: TComponent);
begin
  inherited  Create(AOwner);
   FMainShape:=TShape.Create(AOwner); 
   FMainShape.ControlStyle := FMainShape.ControlStyle + [csAcceptsControls];//
   ControlStyle := ControlStyle + [csAlignWithMargins];   FMainShape.Name  := 'MainShape';
   FMainShape.Brush.Color:=clRed;
   FMainShape.Brush.Style:=bsDiagCross;
   FMainShape.Width := 80;
   FMainShape.Height:= 80;
   FMainShape.Top:=50;
   FMainShape.Left:=10;   FInShape        := TShape.Create(AOwner);
   FMainShape.ControlStyle := FMainShape.ControlStyle + [csAcceptsControls];//
   ControlStyle := ControlStyle + [csAlignWithMargins];
   FInShape.Brush.Color:=clWhite;
   FInShape.Brush.Style:=bsSolid;
   FInShape.Name   := 'InShape';
   FInShape.Width  := 40;
   FInShape.Height := 40;
   FInShape.Left   := FMainShape.Left;
   FInShape.Top    := FMainShape.Top - FInShape.Height;
   FInShape.Refresh;   FPen         := TPen.Create;
   FPen.OnChange:=StyleChanged;
   FBrush         := TBrush.Create;
   FBrush.OnChange:=StyleChanged;end;

解决方案 »

  1.   

    FMainShape.Owner := 窗体名;
    FMainShape.Visible := true;
      

  2.   

    指定你自己创建的控件的parent
    FMainShape.parent := AOwner;FInShape.parent := AOwner;// AOwner是要显示你的shape的控件的地方吧,比如说要显示在form那么aowner就是这个form
      

  3.   

    必须得指定控件的parent属性
    这样才能够在窗体上显示出来!
      

  4.   

    我这是在package里面写的,我预测该控件的parent可能不止1种情况,所以
    我该使用一个什么样的PARENT呢?
    logne()的AOwner要报错,
    Incompatible types :'TWinControl and TComponent';