我还想问一下各位,如果是一组动态的创建的parnel.和一组动态创建的SHAPE,二者创建的时间不是一定是同时的,当然panel肯定是在shape之前创建的,就是说要指明哪明某个SHAPE的PARENT是谁要怎么做?? 比如有若干个车间,每个车间有若干个机器,我用PANEL代表车间,用SHPAE代表机器,所以当我在车间一里增加机器时,那个shape的PARENT就要是车间一的对应的那个PANEL对吧

解决方案 »

  1.   

    在创建shape后,将它的parent属性赋上对应的Panel就好
      

  2.   

    创建 Panel时 把panel的tag设置为 车间的id . 
    创建shape时, 搜索机器所在车间id ,就得到panel 的tag了.
    然后遍历比较tag
      

  3.   

    我想要把那些SHAPE放到panel上呀,我创建SHAPE后,无法将其放到PANEL上,
    procedure TmainF.AddNodeClick(Sender: TObject);
    var
      selectnode: TTreeNode; //±»Ñ¡ÔñµÄ½Úµã
      shape: tshape;
      nonode: integer; //½Úµã±¾ÉíµÄºÅÊý
      noname: string; //½ÚµãÃû³Æ
      sqlstr: string; //sql ÊäÈëÓï¾ä
      chileno: integer; //Ô­½ÚµãÖÐ×Ó½ÚµãµÄ¸öÊý
      panelname: string;
      shapename: string;
      node_id: integer; //µ±Ç°½ÚµãµÄºÅÂë
      panelno: integer;
      ii: integer;
    begin
      selectnode := TreeView1.Selected;
      nonode := TreeView1.Selected.Count; //(0<count<999)
      panelno := 0;
      //  if (selectnode.Text = '&acute;ó&Ocirc;&sup2;&raquo;ú') or (selectnode.Parent.Text = '&acute;ó&Ocirc;&sup2;&raquo;ú') then begin
      if (selectnode.Text = '&acute;ó&Ocirc;&sup2;&raquo;ú') then begin //&Igrave;í&frac14;&Oacute;&sup3;&micro;&frac14;&auml;&ordm;&Aring;
        noname := '&sup3;&micro;&frac14;&auml;' + inttostr(nonode + 1);
        try
          begin
            panelname := 'panel' + inttostr(nonode + 1);
            
            panel[panelno] := tpanel.Create(RzPanel1); //&Igrave;í&frac14;&Oacute;SHAPE
            with panel[panelno] do begin
              parent := mainF;
              name := panelname;
              left := 208;
              TOP := 32;
              height := 500;
              width := 585;
              BEVeLOUTER := BVLOWERED;
              color := clCaptionText;
              // visible:=false;
            end;
          end;
        except
          showmessage('&Igrave;í&frac14;&Oacute;&frac12;&Uacute;&micro;&atilde;&sup3;&ouml;&acute;í&pound;&not;&Ccedil;&euml;&Egrave;·&Egrave;&Iuml;&ordm;ó&Igrave;í&frac14;&Oacute;&pound;&iexcl;');
        end;
      end
      else if (selectnode.parent.Text = '&acute;ó&Ocirc;&sup2;&raquo;ú') then begin
        if (nonode > 8) and (nonode <= 98) then begin //&Egrave;&ccedil;&sup1;&ucirc;&Eacute;è±&cedil;&Igrave;¨&Ecirc;&yacute;&acute;ó&Oacute;&Uacute;9&Igrave;¨&ETH;&iexcl;&Oacute;&Uacute;&micro;&Egrave;&Oacute;&Uacute;98
          if (length(selectnode.Text) = 5) then //&sup3;&micro;&frac14;&auml;&ordm;&Aring;&iexcl;&acute;9
            noname := 'NO' + '0' + copy(selectnode.Text, length(selectnode.Text), 1) + '0' + inttostr(nonode + 1)
          else if (length(selectnode.Text) = 6) then //&sup3;&micro;&frac14;&auml;&ordm;&Aring;>9
            noname := 'NO' + copy(selectnode.Text, length(selectnode.Text) - 1, 2) + '0' + inttostr(nonode + 1);
        end
        else if nonode <= 8 then begin //&Egrave;&ccedil;&sup1;&ucirc;&Eacute;è±&cedil;&Igrave;¨&Ecirc;&yacute;&ETH;&iexcl;&Oacute;&Uacute;9&Igrave;¨
          if (length(selectnode.Text) = 5) then //&sup3;&micro;&frac14;&auml;&ordm;&Aring;&iexcl;&acute;9
            noname := 'NO' + '0' + copy(selectnode.Text, length(selectnode.Text), 1) + '00' + inttostr(nonode + 1)
          else if (length(selectnode.Text) = 6) then //&sup3;&micro;&frac14;&auml;&ordm;&Aring;>9
            noname := 'NO' + copy(selectnode.Text, length(selectnode.Text) - 1, 2) + '00' + inttostr(nonode + 1);
        end
        else if nonode > 98 then begin //&Egrave;&ccedil;&sup1;&ucirc;&Eacute;è±&cedil;&Igrave;¨&Ecirc;&yacute;&acute;ó&Oacute;&Uacute;98&Igrave;¨
          if (length(selectnode.Text) = 5) then //&sup3;&micro;&frac14;&auml;&ordm;&Aring;&iexcl;&acute;9
            noname := 'NO' + '0' + copy(selectnode.Text, length(selectnode.Text), 1) + inttostr(nonode + 1)
          else if (length(selectnode.Text) = 6) then //&sup3;&micro;&frac14;&auml;&ordm;&Aring;>9
            noname := 'NO' + copy(selectnode.Text, length(selectnode.Text) - 1, 2) + inttostr(nonode + 1);
        end;
        try
          begin
            shapename := copy(noname, 2, length(noname) - 1);
            shape := tshape.Create(self);
            with shape do begin
              parent := panel[nonode + 1];
             // parent:=self;
              name := shapename;
              left := 30;
              TOP := 30;
              height := 300;
              width := 300;
              shape := stCircle;
              brush.color := cllime;
              brush.Style := bssolid;
            end;
          //   showmessage(panel[nonode+1].Parent.name );
          end;
        except
          showmessage('&frac12;&Uacute;&micro;&atilde;&Igrave;í&frac14;&Oacute;&sup3;&ouml;&acute;í&pound;&not;&Ccedil;&euml;&Egrave;·&Egrave;&Iuml;&ordm;ó&Igrave;í&frac14;&Oacute;&pound;&iexcl;');
        end;
      end;
    end;
    这是我创建SHAPE和panel的代码,请各位看看现在shape有创建,可是看不到,为什么呢?????
      

  4.   

    以上的代码不太清楚我删了一些你们看这个可能比较好点:
    procedure TmainF.AddNodeClick(Sender: TObject);
    var 
      noname: string; 
      panelname: string;
      shapename: string;
      panelno: integer;
      ii: integer;
    begin
      selectnode := TreeView1.Selected;
      nonode := TreeView1.Selected.Count; //(0<count<999)
      panelno := 0;
      if (selectnode.Text = '&acute;ó&Ocirc;&sup2;&raquo;ú') then begin //这也只是一个添加nonode_name 的地方
        noname := '&sup3;&micro;&frac14;&auml;' + inttostr(nonode + 1);
        try
          begin
            panelname := 'panel' + inttostr(nonode + 1);
            panel[panelno] := tpanel.Create(RzPanel1); //&Igrave;í&frac14;&Oacute;SHAPE
            with panel[panelno] do begin
              parent := mainF;
              name := panelname;
              left := 208;
              TOP := 32;
              height := 500;
              width := 585;
              BEVeLOUTER := BVLOWERED;
              color := clCaptionText;
              // visible:=false;
            end;
          end;
        except
          showmessage('&Igrave;í&frac14;&Oacute;&frac12;&Uacute;&micro;&atilde;&sup3;&ouml;&acute;í&pound;&not;&Ccedil;&euml;&Egrave;·&Egrave;&Iuml;&ordm;ó&Igrave;í&frac14;&Oacute;&pound;&iexcl;');
        end;
      end
      else if (selectnode.parent.Text = '&acute;ó&Ocirc;&sup2;&raquo;ú') then begin
           nonode_name:=          //这儿只是一个添加nonode_name 的地方
           end;
        try
          begin
            shapename := copy(noname, 2, length(noname) - 1);
            shape := tshape.Create(self);
            with shape do begin
              parent := panel[nonode + 1];
             // parent:=self;
              name := shapename;
              left := 30;
              TOP := 30;
              height := 300;
              width := 300;
              shape := stCircle;
              brush.color := cllime;
              brush.Style := bssolid;
            end;
          //   showmessage(panel[nonode+1].Parent.name );
            TreeView1.Items.AddChild(selectnode, noname);
          end;
        except
          showmessage('&frac12;&Uacute;&micro;&atilde;&Igrave;í&frac14;&Oacute;&sup3;&ouml;&acute;í&pound;&not;&Ccedil;&euml;&Egrave;·&Egrave;&Iuml;&ordm;ó&Igrave;í&frac14;&Oacute;&pound;&iexcl;');
        end;
      end;
    end;
    我的PANEL和shape 不是同时创建的,所以把shape定父亲的时候老是出错。
      

  5.   

    shape := tshape.Create(your panel);
      

  6.   

    创建shape后
    shape.parent := panel
      

  7.   

    to zhaohui_1981用了人的办法还是不行的,还是看不到创建后的SHAPE
    to 无风雪亦飘 我的SHAPE和PANEL不是同一个时候创建的
      

  8.   

    给Shape赋Parent值时先检查一下Panel是否存在不存在的话实例化一个先
      

  9.   

    to cscer:
           能不能具体一点