F
fhuibo
Unregistered / Unconfirmed
GUEST, unregistred user!
我用的是递归,代码如下,但是如果节点太多的话很慢,怎么用其他发放实现:<br>type<br> PWARMRecord = ^TWarmRecord; //数据结构<br> TWarmRecord = record<br> bmid: string;<br> bmdm: string; //部门代码<br> bmmc: string; //部门名称<br> Code: string;<br> sjbm: string;<br> end;<br><br>procedure TForm_BmjgSz.NewDataToTreenode;<br>var<br> MySQL: string;<br> MyNode: TTreeNode;<br> MyRecord: PWARMRecord;<br>begin<br> TreeVbm.Items.Clear;<br> MySQL := 'SELECT * FROM TBM WHERE SJBM=''UN'' ORDER BY XSSX';<br> with ADOQBm do<br> begin<br> Close;<br> SQL.Clear;<br> SQL.Text := MySQL;<br> Open;<br> while not eof do<br> begin<br> New(MyRecord);<br> MyRecord.bmid := trim(FieldByName('BMID').AsString);<br> MyRecord.bmdm := trim(FieldByName('BMDM').AsString);<br> MyRecord.bmmc := trim(FieldByName('BMMC').AsString);<br> MyRecord.Code := Trim(FieldByName('CODE').AsString);<br> MyRecord.sjbm := Trim(FieldByName('SJBM').AsString); <br> MyNode := TreeVbm.Items.AddObject(nil,FieldByName('BMMC').AsString, nil); //增加第一层<br> ReadNode(MyNode,FieldByName('BMDM').AsString);<br> MyNode.ImageIndex := 0; //<br> MyNode.SelectedIndex := 3; //<br> Next;<br> end;<br> end;<br>end;<br><br>//遍历树结构<br>procedure TForm_BmjgSz.ReadNode(FNode: TTreeNode; FSJBM: string);<br>var<br> MySQL: string;<br> MyNode: TTreeNode;<br> MyRecord: PWARMRecord;<br> ADOQNode: TADOQuery;<br>begin<br> MySQL := 'SELECT * FROM TBM WHERE SJBM='''+FSJBM+''' ORDER BY XSSX';<br> ADOQNode := TADOQuery.Create(Self);<br> ADOQNode.Connection := DM.ADOConn;<br> with ADOQNode do<br> begin<br> Close;<br> SQL.Clear;<br> SQL.Text := MySQL;<br> Open;<br> while not eof do<br> begin<br> new(MyRecord);<br> MyRecord.bmid := trim(FieldByName('BMID').AsString);<br> MyRecord.bmdm := trim(FieldByName('BMDM').AsString);<br> MyRecord.bmmc := trim(FieldByName('BMMC').AsString);<br> MyRecord.Code := Trim(FieldByName('CODE').AsString);<br> MyRecord.sjbm := Trim(FieldByName('SJBM').AsString);<br> MyNode := TreeVbm.Items.AddChildObject(FNode,MyRecord.bmmc,MyRecord);<br> if FieldByName('Code').AsString = 'UN' then<br> begin<br> MyNode.ImageIndex := 0;<br> MyNode.SelectedIndex := 3;<br> end<br> else<br> begin<br> MyNode.ImageIndex := 1;<br> MyNode.SelectedIndex := 2;<br> end;<br> ReadNode(MyNode,MyRecord.bmdm);<br> Next;<br> end;<br> end;<br>end;