拜托,能帮我看看这里面有什么问题,为什么不能增加子节点呢??
谢谢!

procedure Tcpgy_form.Button1Click(Sender: TObject);
var
 counter,x,kg_flag,restr,addtxtlength:integer;
 addtxt,nodetext,jqstr,addtxtjq:string;
 mynode:TTreeNode;
begin
 insflag:=1
 counter:=0;
 x:=0;
 kg_flag:=0;
 received:=hometrv.selected.count;
 mynode:=hometrv.selected;
 while  counter<received do
   begin
     if hometrv.selected.item[x].Text=edit1.Text then
       begin
       showmessage('产品名称重复!');
       kg_flag:=1;
       edit1.SetFocus;
       end;
     x:=x+1;
     counter:=counter+1;
   end;
   addchild(hometrv.Selected.AbsoluteIndex,edit1.Text);
   edit1.Text:=inttostr(received)
   edit1.Text:=inttostr(kg_flag);
   if  kg_flag=0 then
     begin
       addtxt:=trim(edit1.Text);
       addtxtlength:=length(addtxt);
       nodetext:=trim(hometrv.selected.Text);
       restr:=length(nodetext);
       jqstr:=copy(nodetext,1,restr);
       addtxtjq:=copy(addtxt,1,restr);
       if hometrv.Selected.Level=0 then
           begin
           if edit1.Text='' then
           showmessage('产品名称不能为空!')
           else
           hometrv.Items.AddChild(mynode,mynode.Text);
           end;
   else
     begin
      if  addtxtlength>jqstr then
        begin
          if  addtxtjq=jqstr then
          hometrv.Items.AddChild(mynode,mynode.Text);
        end
      else
         showmessage('产品输入错误');
      end;
   end;
   botton3.Enabled=true;
end;


procedure Tcpgy_form.Button5Click(Sender: TObject);
var
ljmc:integer;
begin
  if hometrv.Selected.Level=0 then
  showmessage('根节点不能删除!')
  else
    begin
      if hometrv.Selected.HasChildren=true then
       showmessage('该节点存在子节点,请删除全部子节点后再删除!')
    else
      begin
        try
          ljmc:=Query1.FieldByName('ljmc').as string;
          if messageDlg('确认要删除选种的记录吗?',mtconfirmation,[mbyes,mbno,0],0)=mryes then
            begin
               hometrv.selected.delete;
               edit1.clear;
               edit2.clear;
               edit3.clear;
               edit4.clear;
               edit5.clear;
               with TQuery.Create(nil) do
               begin
                 try
                 close;
                 SessionName:=main_form.Database1.SessionName;
                 DatabaseName:=main_form.Database1.DatabaseName;
                 SQL.Clear;
                 SQL.Add('delete from [ljgyb] where ljmc='"+ljmc+"');
                 ExecSQL;
                 SQL.Clear;
                 SQL.Add('delete from [ljglb] where ljmc='"+ljmc+"');
                 ExecSQL;
                 finally
                 Free;
               end;
             end;
         end;
     except;
     end;
   end;
end;