In this example:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, comctrls, stdctrls, grids, extctrls; Type tform1 = Class (tform) treeview1: handler; button1: tbutton; button2: tbutton; button3: tbutton; button4: tbutton; Procedure handle (Sender: tobject); Procedure handle (Sender: tobject); Procedure button4click (Sender: tobject); Procedure button5click (Sender: tobject); Procedure destroy (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} procedure tform1.formcreate (Sender: tobject); var nodes: ttreenodes; node: ttreenode; begin treeview1.align: = alleft; nodes: = treeview1.items; node: = nodes. add (nil, 'one-line extension'); node: = nodes. addchild (node, 'one-row length'); node: = nodes. addchild (node, 'one banle'); node: = nodes. addchild (node, 'warrior 1'); nodes. add (node, 'warrior 2'); nodes. add (node, 'warrior 3'); nodes. add (node, 'warrior 4'); node: = node. parent; nodes. add (node, 'second banker'); nodes. add (node, 'three monitors '); node: = node. parent; nodes. add (node, 'second platoon length'); nodes. add (node, 'three platoon length'); node: = node. parent; nodes. add (node, 'two-link extension'); nodes. add (node, 'three connections length'); end; {initialization} procedure tform1.button1click (Sender: tobject); begin treeview1.items. clear; formcreate (NiL); tbutton (sender ). caption: = 'initialization'; end; {Delete} procedure tform1.button2click (Sender: tobject); var node: ttreenode; begin if not Boolean (treeview1.items) Then exit; {If treeview1 has no content} If treeview1.selectioncount = 0 Then exit; {if not selected} node: = treeview1.selected; node. delete; tbutton (sender ). caption: = 'delete'; end; {delete all its subordinates} procedure tform1.button3click (Sender: tobject); var node: ttreenode; begin if not Boolean (treeview1.items) Then exit; if treeview1.selectioncount = 0 Then exit; node: = treeview1.selected; If node. haschildren then node. deletechildren else showmessage (node. text + 'no subauthorization'); tbutton (sender ). caption: = 'delete submit'; end; {Delete with ttreenodes} procedure tform1.button4click (Sender: tobject); var node: ttreenode; begin if not Boolean (treeview1.items) Then exit; if treeview1.selectioncount = 0 Then exit; node: = treeview1.selected; treeview1.items. delete (node); tbutton (sender ). caption: = 'delete with ttreenodes '; end; {insert, only through ttreenodes} procedure tform1.button5click (Sender: tobject); var node: ttreenode; begin if not Boolean (treeview1.items) then exit; If treeview1.selectioncount = 0 Then exit; node: = treeview1.selected; treeview1.items. insert (node, 'new Member '); tbutton (sender ). caption: = 'insert'; end.