Saturday, August 22, 2020

Store More Custom Data Into Tree Node in Delphi

Store More Custom Data Into Tree Node in Delphi The TTreeView Delphi part shows a various leveled rundown of things tree hubs. A hub is introduced by hub content and a discretionary picture. Every hub in a tree see is an example of a TTreeNode class. While you can fill in the tree see with things at configuration time, utilizing the TreeView Items Editor, as a rule you would fill your tree see at run time-depending what your application is about. The TreeView Items Editor uncovers theres just a bunch of data you can connect to a hub: content and a couple of picture records (for the ordinary state, extended, chose and the same). Basically, the tree see part is anything but difficult to program against. There are a few techniques to add new hubs to the tree and set their chain of importance. Heres how to add 10 hubs to the tree see (named TreeView1). Note that the Items property gives access to all hubs in the tree. The AddChild adds another hub to the tree see. The main parameter is the parent hub (to develop the pecking order) and the subsequent parameter is the hub content. The AddChild restores the recently included TTreeNode. In the above code test, every one of the 10 hubs are included as root hubs (have no parent hub). In any increasingly intricate circumstances you would need your hubs to convey more data ideally to have some exceptional qualities (properties) that are explicit to the venture you are creating. Let's assume you need to show client request thing information from your database. Every client can have more requests and each request is made up from more things. This is a progressive connection one can show in a tree see: In your database there would be more information for each request and for every thing. The tree see shows the (read just) current state - and you need to see per request (or even per thing) subtleties for the chose request. At the point when the client chooses the hub Order_1_1 you need the request subtleties (all out aggregate, date, and so on) to get showed to the client. You can, around then get the necessary information from the database, BUT you would need to know the remarkable identifier (lets state a whole number estimation) of the chose request to get the right information. We need an approach to store this request identifier alongside the hub however we can't utilize the Text property. The custom worth we have to store in every hub is a whole number (only a model). At the point when such a circumstance happens you may be enticed to search for the Tag property (numerous Delphi segments have) yet the Tag property isn't uncovered by the TTreeNode class. Add Custom Data To Tree Nodes:Â The TreeNode.Data Property The Data property of a tree hub permits you to connect your custom information with a tree hub. Information is a pointer and can highlight articles and records. The Displaying XML (RSS Feed) Data in a TreeView tells the best way to store a record type variable into the Data property of a tree hub. Some thing type classes uncover the Data property-you can use to store any object alongside the thing. A model is the TListItem of a TListView segment. Heres how to add articles to the Data property. Add Custom Data To Tree Nodes:Â The TreeView.CreateNodeClass In the event that you would prefer not to utilize the Data property of the TTreeNode, yet rather you might want to have your own TreeNode stretched out with a couple of properties, Delphi additionally has an answer. Let's assume you need to have the option to do Heres how to expand the standard TTreeNode with a couple of properties of your own: Make your TMyTreeNode by expanding the TTreeNode.Add it a string property MyProperty.Handle the OnCreateNodeClass for the tree view to determine your hub class ought to be created.Expose something like TreeView1_SelectedNode property on the structure level. This would be of type TMyTreeNode.Handle tree sees OnChange to keep in touch with the SelectedNode the estimation of the hub that is selected.Use TreeView1_Selected.myProperty to peruse or compose new custom worth. Heres the full source code (TButton: Button1 and TTreeView: TreeView1 on a structure): This time the Data property of the TTreeNode class isn't utilized. Or maybe, you stretch out the TTreeNode class to have your own form of a tree hub: TMyTreeNode. Utilizing the OnCreateNodeClass occasion of the tree see, you make a hub of your custom class rather than the standard TTreenode class.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.