for   i:=0   to   TreeView1.Items.Count-1   do
      if   TreeView1.Items[0].Item[i].Text=c_str   then
      begin
              TreeView1.Items[0].Item[i].Delete;
              exit;
      end;每次Delete都是最后一个.不知道为什么

解决方案 »

  1.   

    delete有重后向前,否则很容易出错的,你这样每次删除 count都会变化
      

  2.   

    删除的话要倒着来for i:=TreeView1.Items.Count-1 downto 0 do
      if TreeView1.Items[0].Item[i].Text=c_str then
      begin
      TreeView1.Items[0].Item[i].Delete;
      exit;
      end;
      

  3.   

    因为删除了之后调用了exit,所以和遍历顺序无关,而至楼主用错了count的对象
    for i:=0 to TreeView1.Items[0].Count-1 do  //是Items[0]的子节点个数,不是总个数
      if TreeView1.Items[0].Item[i].Text=c_str then
      begin
      TreeView1.Items[0].Item[i].Delete;
      exit;
      end;
      

  4.   

    删除的话,会引起Count变化,最好用downto
      

  5.   

    占个位置
    继续努力学习中..........
    顶顶帖子,接分中........顶顶帖子,高手们也请多多赐教
    http://topic.csdn.net/u/20110913/13/59f92d11-1fb0-4b7e-9c4a-e93d8f19c689.html
    http://topic.csdn.net/u/20110611/12/3258c959-4f28-46b7-b5d6-46135d73036b.html
    http://topic.csdn.net/u/20110722/14/89f7440b-c4d7-4c9a-a4bb-a503f5135db2.html
    http://topic.csdn.net/u/20110729/10/a7bfaf06-0cf9-4580-8e91-d4e0b92066c6.html
    http://topic.csdn.net/u/20110811/16/e56e7cc1-d8c9-40af-92e3-c24ca103d17d.html
    http://topic.csdn.net/u/20110830/13/dfae4ca5-d2b9-4889-8a3c-6f7fb61936c9.html
    http://topic.csdn.net/u/20110905/12/a1161adb-8e5d-491a-b302-c9722edf2dab.html
    http://topic.csdn.net/u/20110913/16/2dbcc9db-8f71-40c5-901f-afae9026f7c2.html
    http://topic.csdn.net/u/20110913/13/59f92d11-1fb0-4b7e-9c4a-e93d8f19c689.html