F
flashwolf
Unregistered / Unconfirmed
GUEST, unregistred user!
遇到一问题,表中有两个字段
userid和parentid,userid表示用户名,parentid表示userid的上一级用户的用户名。
现在要用fctreeview建一个treeview的树。
原先用一种递归算法,但数据超过100条后运行就非常非常的慢,要等半天树才显示。
有何好办法?
附:原来的代码:
procedure TMainForm.CreateMyTree();
var
TreeNode: TfcTreeNode;
tmpsql: string;
node_num: Integer;
// 节点序号
begin
Current_uID := GUserId;
Current_uName := GUserName;
Current_GrpID := 0;
// departid := '';
tmpsql := 'select * from user_info';
with dm1.qryuser_info do
begin
Close;
SQL.Clear;
SQL.Add(tmpSql);
Open;
First;
end;
TVManager.Items.Clear;
{ remove any existing nodes }
node_num := 0;
TreeNode := nil;
CreateNode(@node_num, '', TreeNode);
end;
///////////////////////////
procedure TmainForm.CreateNode(node_num: PInteger;
parent: string;
TreeNode: TfcTreeNode);
var
userid, ChildName: string;
RecordCount: integer;
IsFirstChild: boolean;
begin
RecordCount := 0;
IsFirstChild := True;
dm1.qryuser_info.First;
while not dm1.qryuser_info.eof do
begin
if dm1.qryuser_info.fieldbyname('flag').asinteger <> 1 then
begin
with TVManager.Items do
begin
if (Trim(dm1.qryuser_info.fieldbyname('parentid').asstring) = parent) then
begin
ChildName := Trim(dm1.qryuser_info.fieldbyname('name').asstring);
if IsFirstChild then
begin
TreeNode := AddChild(TreeNode, ChildName);
IsFirstChild := False;
end
else
TreeNode := Add(TreeNode, ChildName);
userid := Trim(dm1.qryuser_info.fieldbyname('userid').asstring);
TVManager.items[node_num^].StringData := userid;
// 将登录用户设为初始节点
if userid = GUserId then
GUserNode := TreeNode;
node_num^ := node_num^ + 1;
CreateNode(node_num, userid, TreeNode);
end;
end;
end;
RecordCount := RecordCount + 1;
dm1.qryuser_info.First;
dm1.qryuser_info.moveby(RecordCount);
end;
end;
userid和parentid,userid表示用户名,parentid表示userid的上一级用户的用户名。
现在要用fctreeview建一个treeview的树。
原先用一种递归算法,但数据超过100条后运行就非常非常的慢,要等半天树才显示。
有何好办法?
附:原来的代码:
procedure TMainForm.CreateMyTree();
var
TreeNode: TfcTreeNode;
tmpsql: string;
node_num: Integer;
// 节点序号
begin
Current_uID := GUserId;
Current_uName := GUserName;
Current_GrpID := 0;
// departid := '';
tmpsql := 'select * from user_info';
with dm1.qryuser_info do
begin
Close;
SQL.Clear;
SQL.Add(tmpSql);
Open;
First;
end;
TVManager.Items.Clear;
{ remove any existing nodes }
node_num := 0;
TreeNode := nil;
CreateNode(@node_num, '', TreeNode);
end;
///////////////////////////
procedure TmainForm.CreateNode(node_num: PInteger;
parent: string;
TreeNode: TfcTreeNode);
var
userid, ChildName: string;
RecordCount: integer;
IsFirstChild: boolean;
begin
RecordCount := 0;
IsFirstChild := True;
dm1.qryuser_info.First;
while not dm1.qryuser_info.eof do
begin
if dm1.qryuser_info.fieldbyname('flag').asinteger <> 1 then
begin
with TVManager.Items do
begin
if (Trim(dm1.qryuser_info.fieldbyname('parentid').asstring) = parent) then
begin
ChildName := Trim(dm1.qryuser_info.fieldbyname('name').asstring);
if IsFirstChild then
begin
TreeNode := AddChild(TreeNode, ChildName);
IsFirstChild := False;
end
else
TreeNode := Add(TreeNode, ChildName);
userid := Trim(dm1.qryuser_info.fieldbyname('userid').asstring);
TVManager.items[node_num^].StringData := userid;
// 将登录用户设为初始节点
if userid = GUserId then
GUserNode := TreeNode;
node_num^ := node_num^ + 1;
CreateNode(node_num, userid, TreeNode);
end;
end;
end;
RecordCount := RecordCount + 1;
dm1.qryuser_info.First;
dm1.qryuser_info.moveby(RecordCount);
end;
end;