在程序中有句:
    AAA.Parent := GroupSubj[i].Name;
    正常情况:AAA.Parent := gbx1; 那没问题,组件AAA可以在gbx1下生成;
             AAA.Parent := gbx2; 那没问题,组件AAA可以在gbx1下生成;
    但是我的GroupSubj[i].Name是一个动态生成的有多个, 而且该值是一个字符串,因此上面的一句AAA.Parent := GroupSubj[i].Name报错.
   也就是说,如果GroupSubj[i].Name='gbx1',那么 AAA.Parent := 'gbx1';
   
   现在问题是,用什么语句能使得AAA.Parent := GroupSubj[i].Name;中的字符串去掉.....
  

解决方案 »

  1.   

    findComponent
    或者使用工厂模式
      

  2.   

    if Form1.FindComponent(GroupSubj[i].Name) is TGroupBox then
      AAA.Parent := FindComponent(GroupSubj[i].Name)
      

  3.   

    if Form1.FindComponent(GroupSubj[i].Name) is TGroupBox then
      AAA.Parent := TGroupBox(FindComponent(GroupSubj[i].Name))
      

  4.   

    老冯,赞你一个! 组件的parent必须是一个component,不是字符串,如果你保留了父类代码的name,就像楼上老冯哥哥所说的那样
      

  5.   

    function TForm1.GetObject(ParentObject:TObject;AObjectName:string): TObject;
    var
      Field: ^TGroupBox;
    begin
      Result:=nil;
      if ParentObject <> nil then
      begin
        Field := ParentObject.FieldAddress(AObjectName);
        if Field <> nil then
        begin
          result:=Field^;
        end;
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      o:TObject;
    begin
      o:=GetObject( self, 'GroupBox1' );
      self.Label1.Parent:=TGroupBox(o);
    end;:)