帮我看一下代码:
Node:=Form2.TreeView1.Items.Item[0];
For j:=0 to Form2.iii-1 do
begin
s := TStringList.Create;
ListDirs(Form2.Filmno[j], s);
for k:=0 to s.Count-1 do
begin
Form2.TreeView1.Items.AddChild(Node,s.Strings[k]);
end;
s.Free;
While node.Parent.GetNextSibling <> nil do
node := node.Parent.GetNextSibling;
end;
原来我是这样写的:
For j:=0 to Form2.iii-1 do
begin
s := TStringList.Create;
ListDirs(Form2.Filmno[j], s);
Node:=Form2.TreeView1.Items.Item[j];
for k:=0 to s.Count-1 do
begin
Form2.TreeView1.Items.AddChild(Node,s.Strings[k]);
end;
s.Free;
// While node.Parent.GetNextSibling <> nil do
// node := node.Parent.GetNextSibling;
end;
结果是记录都是望第一个父结点中加,行成了很多层。
Form2.Treeview1.loadfromfile('d:/tt.txt'); //调入父结点
iii:=Form2.Treeview1.items.count; //父结点个数
For j:=0 to Form2.iii-1 do
begin
s := TStringList.Create;
ListDirs(Form2.Filmno[j], s);
Node:=Form2.TreeView1.Items.Item[j];
for k:=0 to s.Count-1 do
begin
Form2.TreeView1.Items.AddChild(Node,s.Strings[k]);//加如子结点
end;
s.Free;
While node.Parent.GetNextSibling <> nil do //焦点移到下一个父结点。[red]这里有问题[/red]
node := node.Parent.GetNextSibling;
end;
以下是我成功的代码:
procedure TForm1.Button1Click(Sender: TObject);
var
lst:TStrings;
i,j:integer;
begin
Treeview1.loadfromfile('d:/temp/delphi/cc.txt');
lst:=TStringList.create;
for i:=treeview1.items.count-1 downto 0 do
begin
lst.LoadFromFile('d:/temp/delphi/'+treeview1.items.text);
for j:=0 to lst.count -1 do
begin
treeview1.Items.addchild(treeview1.Items,lst.Strings[j] );
end;
end;
lst.free
end;