Treeview| notes the TreeView is composed of nodes, and the contribution is done by manipulating the Treeview.items attribute. Items are a Ttreenodes object, which is a ttreenode set.
One, for ttreenodes, namely Treeview.items, have these attributes:
1, count, number of nodes.
2, Item[index], through the index to get nodes.
Second, for the Ttreenodes, that is, treeview.items, commonly used to add nodes of the operation are:
AddFirst Add the first root node. The node that is added by this function is always in front of you, and unless you later add a node using this function, the node that you add later will be in front. This function returns the newly added node.
Addchildfirst adds the first child node, requiring a parent node as its parameter. Returns the newly added node.
Addchild adds a child node that requires a parent node as its parameter. Returns the newly added node.
Add adds a sibling node that requires a sibling node as its parameter. Returns the newly added node.
Third, for the Ttreenodes, that is, treeview.items, commonly used to get the operation of the node is:
Getfirstnode () Gets the root node.
Then, with Ttreenode.getnext (), you can access all the nodes.
V. Event triggers:
When you jump from one node to another, the Ttreeview.onchange event is triggered. In this event, node is passed, which is currently selected.
When you modify the text of a node, the Ttreeview.onedit event is triggered.
Connect nodes to the data corresponding to the nodes
For each ttreenode, there is a data attribute that can hold a pointer. We can use this field to store our own data corresponding to the node.
1. We first define a data structure as a record of the data we want to record. Such as:
Type
Pmydata=^tmydata;
Tmydata=record
sfname:string;
slname:string;
Nindex:integer;
End
2. Then, when creating a number, connect the node and node data:
Procedure Tform1.button1click (Sender:tobject);
Var
Myshuju:pmydata
Cur_node:ttreenode;
Begin
New (MYRECPTR); Remember, be sure to allocate memory first. There are several nodes that need to be allocated memory several times.
myshuju^. Fname:=edit1.text;
myshuju^. LName: = Edit2.text;
Treeviewindex: = Strtoint (Edit3.text);
With TreeView1 do
Begin
Cur_node:=items. AddFirst (Nil, ' a ');
Cur_node.data:=myshuju;
End
End
3. When we select a node, we can use our data.
Procedure Tform1.treeview1change (Sender:tobject; Node:ttreenode);
Begin
If Node.data<>nil Then
Self.label1.caption:=pmydata (node.data) ^. Fname+pmydata (node.data) ^. Lname
End
Seven, the general use of the process:
1. Add Global variables:
B_first:boolean; Whether the record is the first access node, because the data is not ready at this time, and once the Access node triggers the onchange event, there may be an error in this event handler function.
2, in the Formcreate,
A, set up b_first:=true;
B. Create the number and contact the node with the data.
3, in the Formshow
Set B_first:=false;
4. Handle node-selected events in event onchange.
5. Handle node modified text event in edit.
and call onchange.
6. In the Treeview.destory
Releases the memory space pointed to in data.
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