程序如下:
procedure TForm1.FormCreate(Sender: TObject);
function getnode(str: string): TTreeNode;
var
a: array of TTreeNode;
node: TTreeNode;
i, j, count: integer;
begin
i := 0;
j := 0;
if j = -60000 then
showmessage('error');
Count := TreeView1.Items.Count;
setlength(a, Count);
node := TreeView1.TopItem;
while node <> nil do
begin
a[i] := node;
node := node.getNextSibling;
i := i + 1;
end;
j := i - 1;
i := 0;
while i < Count do
begin
node := a[i].getfirstchild;
while node <> nil do
begin
j := j + 1;
a[j] := node;
node := node.getNextSibling;
end;
i := i + 1;
end;
for i := 0 to Count - 1 do
if a[i].text = str then
begin
result := a[i];
exit;
end;
result := nil;
end;
//function init ok!
var
node :TTreeNode;
begin
Adoconnection1.ConnectionString:='provider=Microsoft.Jet.OLEDB.4.0;Data Source'
+ExtractFilePath(ParamStr(0))
+'db\database.mdb;persist Security Info=false';
Adoconnection1.LoginPrompt:=False;
with ADOQuery1 do
begin
adoquery1.Connection:=adoconnection1;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.sql.add(' select * from dwb ');
adoquery1.open;
while not adoquery1.Eof do
begin
node := getNode(adoquery1.FieldByName('部门名称').AsString);
if node = nil then
TreeView1.Items.AddChild(nil, adoquery1.FieldByName('部门名称').AsString)
else
begin
TreeView1.Items.AddChild(Node, adoquery1.FieldByName('个人姓名').AsString);
end;
if node <> nil then
adoquery1.Next;
end;
adoquery1.Close;
end;
end;
end.
procedure TForm1.FormCreate(Sender: TObject);
function getnode(str: string): TTreeNode;
var
a: array of TTreeNode;
node: TTreeNode;
i, j, count: integer;
begin
i := 0;
j := 0;
if j = -60000 then
showmessage('error');
Count := TreeView1.Items.Count;
setlength(a, Count);
node := TreeView1.TopItem;
while node <> nil do
begin
a[i] := node;
node := node.getNextSibling;
i := i + 1;
end;
j := i - 1;
i := 0;
while i < Count do
begin
node := a[i].getfirstchild;
while node <> nil do
begin
j := j + 1;
a[j] := node;
node := node.getNextSibling;
end;
i := i + 1;
end;
for i := 0 to Count - 1 do
if a[i].text = str then
begin
result := a[i];
exit;
end;
result := nil;
end;
//function init ok!
var
node :TTreeNode;
begin
Adoconnection1.ConnectionString:='provider=Microsoft.Jet.OLEDB.4.0;Data Source'
+ExtractFilePath(ParamStr(0))
+'db\database.mdb;persist Security Info=false';
Adoconnection1.LoginPrompt:=False;
with ADOQuery1 do
begin
adoquery1.Connection:=adoconnection1;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.sql.add(' select * from dwb ');
adoquery1.open;
while not adoquery1.Eof do
begin
node := getNode(adoquery1.FieldByName('部门名称').AsString);
if node = nil then
TreeView1.Items.AddChild(nil, adoquery1.FieldByName('部门名称').AsString)
else
begin
TreeView1.Items.AddChild(Node, adoquery1.FieldByName('个人姓名').AsString);
end;
if node <> nil then
adoquery1.Next;
end;
adoquery1.Close;
end;
end;
end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货