应该用不着递归算法。我曾经用以下代码填tree:procedure TForm1.FillAffair();var NodeS, NodeC:TTreeNode; Count, No:Integer; AffairName, AffairSort, AffairStatus:string; FindOutS, FindOutC:boolean;begin //清空Tree TVAffair.Items.Clear; NodeS:=nil; NodeC:=nil; //到数据的第一条 ADODSA1.First; //锁定视图 TVAffair.Items.BeginUpdate; //循环处理数据 while not ADODSA1.Eof do begin //准备 AffairName:=ADODSA1.FieldByName('AffairName').AsString; AffairSort:=ADODSA1.FieldByName('AffairSort').AsString; AffairStatus:=ADODSA1.FieldByName('AffairState').AsString; Count:=TVAffair.Items.Count; No:=0; FindOutS:=False; FindOutC:=False; //查找有无父节点(种类) while No<=Count-1 do begin NodeS:=TVAffair.Items[No]; if (TVAffair.Items[No].Text=AffairStatus)and(TVAffair.Items[No].Level=0) then begin FindOutS:=True; Break; end; No:=No+1; end; //找到父节点 if FindOutS=True then begin //查找有无种类节点(种类) while No<=Count-1 do begin NodeC:=TVAffair.Items[No]; if (TVAffair.Items[No].Text=AffairSort)and(TVAffair.Items[No].Level=1) then begin FindOutC:=True; Break; end; No:=No+1; end; //找到种类节点 if FindOutC=True then NodeC:=TVAffair.Items.AddChild(NodeC, AffairName) //没找到种类节点 else begin NodeC:=TVAffair.Items.AddChild(NodeS, AffairSort); NodeC:=TVAffair.Items.AddChild(NodeC, AffairName); end; end //没找到状态节点 else begin NodeS:=TVAffair.Items.AddChild(nil, AffairStatus); NodeC:=TVAffair.Items.AddChild(NodeS, AffairSort); NodeC:=TVAffair.Items.AddChild(NodeC, AffairName); end; ADODSA1.Next; end; //解除锁定视图 TVAffair.Items.EndUpdate;end;总共有三级node