Z
zhangjensy
Unregistered / Unconfirmed
GUEST, unregistred user!
誰能提供高效的樹顯示算法?
1---基本资料
2---布面料
3----帆布
4------[a0001]10n帆布
3----双拼布
3----麻布
4------[a10002]11b麻布
2----部件
3------[b10003]
2----包装物
各個字節點都保存在數據庫中,現在要一個一個顯示出來,我用一個算法,不過很慢,5000條記錄用了差不多1-2分鐘!算法如下:
procedure Tfrm.FmtTree();
var
i,j :integer;
leafList,leafListPlus: TList;
leaf,subNode: TTreeNode;
tv: TTreeView;//引用窗体控件
qry: TADOQuery;//引用窗体控件
begin
//初始化
leafList:=TList.Create;
leafListPlus:=TList.Create;
tv:=tvw1;
tv.Items.Clear;
qry:=qry1;
subNode:=tv.Items.AddChild(nil,'月夜风筝(我)的公司');
leafList.Add(subNode);
//处理
while leafList.Count > 0 do
begin
leafListPlus.Clear;
for i:=0 to leafList.Count-1 do
begin
leaf:=leafList;
if leaf.Level = 0 then
qry.SQL.Text:=Format('select code,name,belong from TB where belong = ''%s''',['--'])
else
qry.SQL.Text:=Format('select code,Name,belong from TB where belong = ''%d''',[leaf.StateIndex]);
qry.Open;
for j:= 0 to qry.RecordCount-1 do
begin
subNode:=tv.Items.AddChild(leaf,qry.FieldByName('name').AsString);
subNode.ImageIndex:=subNode.Level;
subNode.StateIndex:=StrToInt(qry.FieldByName('code').AsString);
leafListPlus.Add(subNode);
qry.Next;
end;
end;
leafList.Assign(leafListPlus);
end;
//清理
tv.FullExpand;
leafListPlus.Free;
leafList.Free;
end;
誰能幫幫我啊!
1---基本资料
2---布面料
3----帆布
4------[a0001]10n帆布
3----双拼布
3----麻布
4------[a10002]11b麻布
2----部件
3------[b10003]
2----包装物
各個字節點都保存在數據庫中,現在要一個一個顯示出來,我用一個算法,不過很慢,5000條記錄用了差不多1-2分鐘!算法如下:
procedure Tfrm.FmtTree();
var
i,j :integer;
leafList,leafListPlus: TList;
leaf,subNode: TTreeNode;
tv: TTreeView;//引用窗体控件
qry: TADOQuery;//引用窗体控件
begin
//初始化
leafList:=TList.Create;
leafListPlus:=TList.Create;
tv:=tvw1;
tv.Items.Clear;
qry:=qry1;
subNode:=tv.Items.AddChild(nil,'月夜风筝(我)的公司');
leafList.Add(subNode);
//处理
while leafList.Count > 0 do
begin
leafListPlus.Clear;
for i:=0 to leafList.Count-1 do
begin
leaf:=leafList;
if leaf.Level = 0 then
qry.SQL.Text:=Format('select code,name,belong from TB where belong = ''%s''',['--'])
else
qry.SQL.Text:=Format('select code,Name,belong from TB where belong = ''%d''',[leaf.StateIndex]);
qry.Open;
for j:= 0 to qry.RecordCount-1 do
begin
subNode:=tv.Items.AddChild(leaf,qry.FieldByName('name').AsString);
subNode.ImageIndex:=subNode.Level;
subNode.StateIndex:=StrToInt(qry.FieldByName('code').AsString);
leafListPlus.Add(subNode);
qry.Next;
end;
end;
leafList.Assign(leafListPlus);
end;
//清理
tv.FullExpand;
leafListPlus.Free;
leafList.Free;
end;
誰能幫幫我啊!