Recent

Author Topic: VirtualStringTree - how to get node from absolute index?  (Read 14109 times)

Dibo

  • Hero Member
  • *****
  • Posts: 1059
VirtualStringTree - how to get node from absolute index?
« on: December 14, 2012, 06:50:32 pm »
Hi,

Can't find how to get node from index. Am I blind? There is a lot of GetNodeXXXX methods but no one from index. I want delete node and Delete() method need PVirtualNode and I know only index

Regards

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: VirtualStringTree - how to get node from absolute index?
« Reply #1 on: January 26, 2013, 06:58:25 am »
Not sure what you mean by "index".
I always delete a node by focusing on it, then deleting it.

example:
Code: [Select]
procedure TfSNMPGet.mDVDeleteClick(Sender: TObject);
// Delete an individual device ...
var
  DevNode : pVirtualNode;
begin
  If not Assigned(vstDevList.FocusedNode)
    Then Exit
    else
    begin
      DevNode := vstDevList.FocusedNode;
      vstDevList.Selected[DevNode] := True;

      vstDevList.DeleteNode(DevNode);
      vstDevList.Refresh;
    end;
end;    // of mDVDeleteClick       
 

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: VirtualStringTree - how to get node from absolute index?
« Reply #2 on: January 26, 2013, 08:39:03 am »
there is such thing as absolute index for the virtual string tree each it is a tree you need to know the parent and the index in the child if you mean a flat index then the only way to do it is to walk down the tree using depth first until you rich the number you are after and then return that node.

EG.
Code: [Select]
function NodeByIndex(const aTree:TVirtualStringTree; const anIndex:Integer):PVirtualNode;
var
  Cnt : integer;
  Node : PVirtualNode;
begin
  Node := vstTaskTree.GetNext(vstTaskTree.RootNode);
  Cnt := 1;
  while (Node <> nil)  and (Cnt < anIndex) do begin
    Node := vstTaskTree.GetNext(Node);
    Inc(Cnt);
  end;
  Result := Node;//Should Return Nil if the index is not reached.
end;

Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018