我定义了一个类  在窗口中建立的时候不能显示出来  不知道如何  单击按钮建立了类的对象  但类中的label和image不能在窗口中显示出来   高手帮忙
  my2=class(TWinControl)
  private
        tex: Tlabel;
        pic: Timage;
      public
        procedure  init(AOwner: TComponent; AParent:   TWinControl);
      end;implementation
procedure my2.init;
  begin
    tex:=Tlabel.Create(AOwner);
    tex.Parent:=AParent;
    tex.Caption:='hehe';
    tex.Visible:=true;
    pic:=Timage.Create(AOwner);
    pic.Picture.LoadFromFile('logo.jpg');
    pic.Parent:=AParent;
    pic.Visible:=true;
  end;窗口中我是这样使用这个类的
  sz: array of my2;
implementation{$R *.dfm}procedure TForm1.BitBtn1Click(Sender: TObject);
var
  lable: my2;
begin
  i := i + 1;
  SetLength(sz,i);
  lable := my2.Create(self);
  lable.Parent:=form1;
  lable.Top:=i*10;
  lable.Left:=i*6;
  sz[i-1] := lable;
  label1.Caption:=inttostr(i);
end;

解决方案 »

  1.   

    建议你还是找本有关vcl控件编程的教材看一下,这么下去不是个办法
    my2.init在哪里有调用?传入的AOwner和AParent都是什么?
      

  2.   

    你设置了lable: my2的位置,但是没有设置里面的        tex: Tlabel;   pic: Timage; 的位置,从TControl继承的,在设计期是可视的,要不可视的话从TComponent继承吧.
      

  3.   

    用create也是一样  我就这几个关键地方过不去了  大家帮帮忙吧
      

  4.   

    在lable.Parent:=form1;后加一句 
      lable.init(nil,lable.Parent); 
      

  5.   

    lable := my2.Create(self); 并没有触发procedure  init(AOwner: TComponent; AParent:  TWinControl); 你的控件怎么会创建呢 在你的程序中调用lable.init(nil,lable.Parent); 或者在my2类中写构造函数create,把init方法放到create中
      

  6.   

      Tmy2=class(TWinControl)
      private
        tex: Tlabel;
        pic: Timage;
      public
        constructor Create(AOwner: TComponent); override;
      end;
    ....
    { Tmy2 }constructor Tmy2.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      width := 100;
      height := 100;
      tex:=Tlabel.Create(AOwner);
      tex.Parent:=self;
      tex.Caption:='hehe';  pic:=Timage.Create(AOwner);
    //  pic.Picture.LoadFromFile('logo.jpg');
      pic.Parent:=self;end;procedure TForm1.Button8Click(Sender: TObject);
    var
      m:  Tmy2;
    begin
      m := Tmy2.Create(self);
      m.Parent := self;end;
    我的可以显示。