TTreeView lazarus / 13-General ---------------------------------------------------------------------- Ñuño_Martínez · 2009-03-31 13:37 I'm tryin to use a TTreeView but it doesn't work. If I add nodes and subnodes in design time it shows all them with their icons and you can expand and collapse subnodes at runtime, but when I try to do the same at runtime it doesn't show any icon and there's no subnodes.  I've looking for help on the Internet and here but all documents I found assumes that I know how Delphi's TTreenode works, that isn't the case. I did use Delphi for years but I never need a TTreenode before today. Oh, and the wiki page is almost ridiculous! How does the TTreeView work? ---------------------------------------------------------------------- arnoldb · 2009-03-31 15:11 Here is a quick&dirty example - I tested on Windows Lazarus 0.9.26: Create a new application.  On Form1 add an empty treeview, a button1 with caption "Add Child" and a button2 with caption "Delete" for the buttons, assign the following code, compile & run. Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var i:integer;     s:string; begin   //if there is no nodes, create a root node with a parent of Nil   if TreeView1.Items.Count = 0 then     begin       Treeview1.Items.Add (nil,'Root Node');       exit;     end;   //Set up a simple text for each new node - Node1 , Node2 etc   i:=treeview1.Items.Count;   s:= 'Node '+inttostr(i);   //Add a new node to the currently selected node   if TreeView1.Selected <> nil then     Treeview1.Items.AddChild(Treeview1.Selected ,s); end; procedure TForm1.Button2Click(Sender: TObject); var DeleteChildren:Boolean;   //A procedure to recursively delete nodes   Procedure DeleteNode(Node:TTreeNode);   begin     while Node.HasChildren do DeleteNode(node.GetLastChild);     TreeView1.Items.Delete(Node) ;   end; begin   if TreeView1.Selected = nil then exit;   If treeview1.Selected.HasChildren then     if messagedlg('Delete node and all children ?',mtConfirmation,                  [mbYes,mbNo],0) <> mrYes then exit;   DeleteNode(TreeView1.Selected); end;                        When running, the treeview is empty.  If you click "Add Child", a root node is created.  After that a child will be added to any selected node by clicking "Add Child" Delete will delete the currently selected node.  If it doesn't have children, it will delete it immediately, but if it has children, it will first ask. Hope this helps a bit. ---------------------------------------------------------------------- Ñuño_Martínez · 2009-03-31 17:58 Thanks arnoldb. That clarifies a lot. I was doing everything  wrong.  I think somebody must put your example on the wiki so everybody can read it. ---------------------------------------------------------------------- arnoldb · 2009-04-01 06:15 Pleasure  - I also added it to the Wiki.