怎样不用递归列一个分三级的TreeView,急啊!!帮帮我!!我可以给300分的

解决方案 »

  1.   

    写死,呵呵递归的..function TfrmPactItem.LoadNode(pid: Integer; pNode: TTreeNode): Boolean;
    type
      TtmpData = record
        no: string;
        id: Integer;
        pid: Integer;
        title: string;
        content: string;
        attachfile: string;
      end;
    var
      SaveData: array of TtmpData;
      I: Integer;
      RdCount: Integer;
      ChildCount: Integer;
      CurrNode: TTreeNode;
    begin
      Result := False;
      with LoginInf.MySQLPlus do
      begin
        Close;
        SQL.Clear;
        SQL.Add('select id, pid, title, content, no, attachfile from pactitem '
          + 'where pid = ' + IntToStr(pid) + ' and pactno = ''' + FCurrPactNo
          + #39);
        Open;    RdCount := RecordCount;
        SetLength(SaveData, RdCount);    for I := 0 to RdCount - 1 do
        begin
          SaveData[I].id := Fields[0].AsInteger;
          SaveData[I].pid := Fields[1].AsInteger;
          SaveData[I].title := Fields[2].AsString;
          SaveData[I].content := Fields[3].AsString;
          SaveData[I].no := Fields[4].AsString;
          SaveData[I].attachfile := Fields[5].AsString;
          Next;
        end;
        Close;
      end;
      for I := 0 to RdCount - 1 do
      begin
        LoginInf.PactItem[FIndex].id := IntToStr(SaveData[I].id);
        LoginInf.PactItem[FIndex].pid := IntToStr(SaveData[I].pid);
        LoginInf.PactItem[FIndex].title := SaveData[I].title;
        LoginInf.PactItem[FIndex].content := SaveData[I].content;
        LoginInf.PactItem[FIndex].no := SaveData[I].no;
        LoginInf.PactItem[FIndex].currindex := IntToStr(FIndex);
        LoginInf.PactItem[FIndex].haschange := False;
        LoginInf.PactItem[FIndex].attachfile := SaveData[I].attachfile;
        LoginInf.PactItem[FIndex].status := '';    CurrNode := tvMain.Items.AddChild(pNode, SaveData[I].Title);
        CurrNode.Data := PChar(LoginInf.PactItem[FIndex].Currindex);
        Inc(FIndex);
        SetLength(LoginInf.PactItem, FIndex + 1);
        with LoginInf.MySQLPlus do
        begin
          Close;
          SQL.Clear;
          SQL.Add('select count(no) from pactitem where pid = ' +
            IntToStr(SaveData[I].id)
            + ' and pactno = ''' + FCurrPactNo + #39);
          Open;
          ChildCount := Fields[0].AsInteger;
          Close;
        end;    if CurrNode.Parent = nil then
        begin
          CurrNode.ImageIndex := 4;
          CurrNode.SelectedIndex := 5;
        end
        else if ChildCount > 0 then
        begin
          CurrNode.ImageIndex := 2;
          CurrNode.SelectedIndex := 3;
        end
        else
        begin
          CurrNode.ImageIndex := 0;
          CurrNode.SelectedIndex := 1;
        end;    if ChildCount > 0 then
        begin
          LoadNode(SaveData[I].id, CurrNode);
        end;
      end;
      Result := True;
    end;