Learn ttreeview [7]-insert and delete

Source: Internet
Author: User
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.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.