TTreeView nodes Q lazarus / 31-LCL ---------------------------------------------------------------------- Prime · 2013-06-03 12:41 Hi All, I'm trying to convert some code i wrote for Delphi 7 to Lazarus, as I'd like to be able to use it on Linux and Windows.... Anyway in my original Delphi app I am building a TTreeView that collects data about a file system / directory tree (basically so you can click on a directory and it'll tell you how many files / folders below it and the total size). So I have a pretty standard recursive search that collects the data and fills it into the tree nodes, his seems to be working correctly, however I'm having trouble with the viewing part of the problem. My onvew code is : Code: [Select]procedure TForm1.TreeViewClick(Sender: TObject); VAR Node : TTreeNode;         Data : TDirList; begin {$IFNDEF FPC}   Node:=TreeView.Items.GetNode(TreeView.Selected.ItemID); {$ELSE}   Node:=TreeView.Items.Item[TreeView.Selected.Index]; {$ENDIF}   Data:=TDirList(Node.Data);   IF(Data<>NIL) THEN     WITH Data DO       Log('%s Size=%s, Files=%d, Dirs=%d',[PathName,GetSizeEntry(Size),NoFiles,NoDirs]); end; This works in Delphi because the TreeView.Selected.ItemID exists, this doesn't seem to have an equivalent in Lazarus, so I tried using TreeView.Items.Item[TreeView.Selected.Index]; This produces a valid node but it always seems to produce the data for the node 2 above the one I clicked on Does anyone have any idea what is going on here, or how indeed I can fix it Cheers. Phill. ---------------------------------------------------------------------- wp · 2013-06-03 13:04 Quoteseems to produce the data for the node 2 above the one I clicked on I get the impression that you want to determine the node clicked on. This works: Code: [Select]uses   LCLIntf,...; procedure TForm1.TreeView1Click(Sender: TObject); var   P: TPoint;   node: TTreeNode;   tree: TTreeView; begin   tree := TTreeView(Sender);   GetCursorPos(P);   P := tree.ScreenToClient(P);   node := tree.GetNodeAt(P.X, P.Y);   ShowMessage('Clicked node: '+node.Text); end; ---------------------------------------------------------------------- taazz · 2013-06-03 13:16 Code: [Select]{$IFNDEF FPC}   Node:=TreeView.Items.GetNode(TreeView.Selected.ItemID); {$ELSE}   Node:=TreeView.Items.Item[TreeView.Selected.Index]; {$ENDIF} you do understand that this is a long winded way to say Node:=TreeView.Selected right? ---------------------------------------------------------------------- Prime · 2013-06-03 13:22 Quote from: taazz on June 03, 2013, 03:16:02 pmCode: [Select]{$IFNDEF FPC}   Node:=TreeView.Items.GetNode(TreeView.Selected.ItemID); {$ELSE}   Node:=TreeView.Items.Item[TreeView.Selected.Index]; {$ENDIF} you do understand that this is a long winded way to say Node:=TreeView.Selected right? You're quite correct it is, and no I never realized that, I originally copied the viewing code from an online example and tinkered with it till it worked   Because it worked I never investigated any further, but yep TreeView.Selected is much quicker. I tried wp's method also and that works too, and may come in handy sometime if I need to do screen -> list translations. Cheers for the quick replies, much appreciated. Phill. ---------------------------------------------------------------------- wp · 2013-06-03 13:30 My code is a bit more complicated, but returns the clicked node even if the selection does not change (e.g. clicking on the expand icons (+/-).