We help IT Professionals succeed at work.

TVirtualStringTree porblem

gfdas
gfdas asked
on
TVirtualStringTree porblem

In Advanced example there is :

procedure TMainForm.AddButtonClick(Sender: TObject);

var
  Count: Cardinal;
  Start: Cardinal;
 
begin
  Screen.Cursor := crHourGlass;
  with VST1 do
  try
    Start := GetTickCount;
    case (Sender as TButton).Tag of
      0: // add to root
        begin
          Count := StrToInt(NodeCountEdit.Text);
          RootNodeCount := RootNodeCount + Count;
        end;
      1: // add as child
        if Assigned(FocusedNode) then
        begin
          Count := StrToInt(NodeCountEdit.Text);
          ChildCount[FocusedNode] := ChildCount[FocusedNode] + Count;
          Expanded[FocusedNode] := True;
          InvalidateToBottom(FocusedNode);
        end;
    end;
    Label1.Caption := Format('Last operation duration: %d ms', [GetTickCount - Start]);
    Label3.Caption := Format('Nodes in tree: %d', [VST1.TotalCount]);
  finally
    Screen.Cursor := crDefault;
  end;
end;

I am not satisified with it. I want to lear more about PVirtualNode.
Please give me example how to add node at specific position is TVirtualStringTree.
Not by selected node as        
if Assigned(FocusedNode) then
but by code definited Node.

Thanks.
Comment
Watch Question

Author

Commented:
I am sorry !

I am not satisified with it. I want to learn more about PVirtualNode.
Please give me example how to add node at specific position in TVirtualStringTree.
Not by selected node as        
if Assigned(FocusedNode) then
but by code definited Node.

Author

Commented:
For example add child node in column number 5 and
add normal node in column number 3.

Thanks.
Mike Lischke the author has ceased to answer here.
BRONZE EXPERT
Top Expert 2004
Commented:
i use a normal iteration, its fast enough for my needs, meybe it helps you

from a project of mine

Function TF_PResource.FindParent(Tree : TVirtualStringTree; ID,TYP : Integer) : PVirtualNode;
var I : Integer;
    Node : PVirtualNode;
    AData : PItemInfo; //this is a userdefined record
    found : Boolean;
begin
  Result := Nil;
  Node := Tree.GetFirstNode;
  found := False;
  while (Node <> nil) and not(found) do
  begin
    Adata := Tree.GetNodeData(Node);
    found := (AData.ID = ID) and  //the compare is stored in the node data
             (AData.Typ = Typ);
    if not Found then
      Node := Tree.GetNext(Node);
  end;
  If found then
    result := Node;
end;

meikl ;-)