2012-07-13 84 views
3

我想瀏覽一下VirtualTreeView的所有根,並刪除它們。虛擬樹視圖循環

我不想清除它。

我得到一個訪問衝突,此代碼:

var 
Node : PVirtualNode; 
begin 
if VirtualStringTree1.GetFirst = NIL then exit; 
Node := NIL; 
repeat 
    if Node = NIL then 
    Node := VirtualStringTree1.GetLast 
    else Node:=VirtualStringTree1.GetPrevious (Node); 
    if Node <> NIL then VirtualStringTree1.DeleteNode(Node); 
until Node = VirtualStringTree1.GetFirst; 
end; 

謝謝您的幫助。

+5

什麼是結算清單,並刪除所有的區別節點? – 2012-07-13 10:08:04

+1

RootNodeCount如何:= 0? – 2012-07-13 14:35:22

+0

rootnodecount:= 0聽起來不錯。不同之處在於在刪除它們之前,我需要從根節點獲取一些數據。 – 2012-07-13 16:29:30

回答

8

實施中存在邏輯錯誤:刪除節點後,本地變量Node指向不存在的節點。

我不明白你爲什麼不想只是清除樹,但你可以從上刪除所有節點,首先是這樣的:

var 
    Node, TmpNode: PVirtualNode; 
begin 
    Node := Tree.GetLast; 
    while Assigned(Node) do 
    begin 
    TmpNode := Tree.GetPrevious(Node); 
    Tree.DeleteNode(Node); 
    Node := TmpNode; 
    end; 
end; 
+0

這工作就像一個魅力謝謝你。你是對的我完全忘記了這一點。 – 2012-07-13 07:53:54