我想创建一个继承了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;
但是为什么显示不出来呢?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;
FMainShape.Visible := true;
FMainShape.parent := AOwner;FInShape.parent := AOwner;// AOwner是要显示你的shape的控件的地方吧,比如说要显示在form那么aowner就是这个form
这样才能够在窗体上显示出来!
我该使用一个什么样的PARENT呢?
logne()的AOwner要报错,
Incompatible types :'TWinControl and TComponent';