有一数据字段,值为 '临床一般检验/血液一般检查/比重'
                '临床一般检验/血液一般检查/红细胞计数'
                '临床一般检验/体液一般检验/外观'
                '临床生物化学检验/葡萄糖及其代谢的检验/酮体'
                '临床免疫学检验/肿瘤标志物检验/癌胚抗原'
                '临床免疫学检验/肿瘤标志物检验/端粒酶'
我想把它生成树(TreeView)
结构如下:
               临床一般检验
                      血液一般检查
                           比重
                           红细胞计数
                        外观
                 临床生物化学检验
                      葡萄糖及其代谢的检验 
                           酮体
                 临床免疫学检验 
                      肿瘤标志物检验
                           癌胚抗原
                           端粒酶
......先谢谢各位了!
                        
                

解决方案 »

  1.   

    结合Pos和Copy函数先将结构分出来,然后写树就好办了
      

  2.   

    也可以使用instr/substring在数据库返回的时候就形成一个表
      

  3.   


    //写个过程给你
    procedure ProcessLine(tv:TTreeView;text:String);
    var
      i:Integer;
      found:Boolean;
      str1,str2,str3:string;
      node1,node2,node3:TTreeNode;
    begin
      i:=pos('/',text);
      str1:=copy(text,1,i-1);
      text:=copy(text,i+1,length(text)-i);
      i:=pos('/',text);
      str2:=copy(text,1,i-1);
      str3:=copy(text,i+1,length(text)-i);  //一级节点
      node1:=tv.Items.GetFirstNode;
      found:=false;
      while node1<>nil do
      begin
        if node1.Text=str1 then
        begin
          found:=true;
          Break;
        end;
        node1:=node1.GetNext;
      end;
      if not found then
        node1:=tv.Items.Add(nil,str1);  //二级节点
      node2:=node1.getFirstChild;
      found:=false;
      while node2<>nil do
      begin
        if node2.Text=str2 then
        begin
          found:=true;
          Break;
        end;
        node2:=node2.GetNext;
      end;
      if not found then
        node2:=tv.Items.AddChild(node1,str2);
      //三级节点
      node3:=node2.getFirstChild;
      found:=false;
      while node3<>nil do
      begin
        if node3.Text=str3 then
        begin
          found:=true;
          Break;
        end;
        node3:=node3.GetNext;
      end;
      if not found then
        node3:=tv.Items.AddChild(node2,str3)end;
    //调用
      ProcessLine(TreeView1,'临床一般检验/血液一般检查/比重');
      ProcessLine(TreeView1,'临床一般检验/血液一般检查/红细胞计数');
      ProcessLine(TreeView1,'临床一般检验/体液一般检验/外观');
      ProcessLine(TreeView1,'临床生物化学检验/葡萄糖及其代谢的检验/酮体');
      ........