大家好,请看以下代码:
procedure TForm1.Button1Click(Sender: TObject);var
  MyTreeNode1, MyTreeNode2: TTreeNode;
begin
  with TreeView1.Items do
  begin
    Clear; { remove any existing nodes }
    MyTreeNode1 := Add(nil, 'RootTreeNode1'); { Add a root node }
    { Add a child node to the node just added }
    AddChild(MyTreeNode1,'ChildNode1');    {Add another root node}
    MyTreeNode2 := Add(MyTreeNode1, 'RootTreeNode2');
    {Give MyTreeNode2 to a child }
    AddChild(MyTreeNode2,'ChildNode2');    {Change MyTreeNode2 to ChildNode2 }
    { and add a child node to it}
    MyTreeNode2 := TreeView1.Items[3];    AddChild(MyTreeNode2,'ChildNode2a');    {Add another child to ChildNode2, after ChildNode2a }
    Add(MyTreeNode2,'ChildNode2b');    {add another root node}
    Add(MyTreeNode1, 'RootTreeNode3');  end;
  showmessage('TreeView1.Items[3].Text:' + TreeView1.Items[3].Text);
end;end.
请问在以上程序当中为什么TreeView1.Items[3]会是ChildNode2,而不是RootTreeNode3吗?而且通过跟踪发
TreeView1.Items[1] = childNode1,TreeView1.Items[2]= RootTreeNode,请问这是为什么?