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 segment shows a progressive rundown of things tree hubs. A hub is introduced by hub content and a discretionary picture. Every hub in a tree see is a case of a TTreeNode class. While you can fill in the tree see with things at configuration time, utilizing the TreeView Items Editor, by and large 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 append to a hub: content and a couple of picture files (for the typical state, extended, chose and the same). Fundamentally, the tree see segment is anything but difficult to program against. There are a few strategies 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 principal parameter is the parent hub (to develop the progression) 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 progressively unpredictable circumstances you would need your hubs to convey more information ideally to have some exceptional qualities (properties) that are explicit to the undertaking 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 various leveled 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 total, date, and so forth) to get showed to the client. You can, around then get the necessary information from the database, BUT you would need to know the novel 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 yet 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) however 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 items 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 items to the Data property. Add Custom Data To Tree Nodes:Â The TreeView.CreateNodeClass On the off chance that you would prefer not to utilize the Data property of the TTreeNode, yet rather you might want to have your own TreeNode reached out with a couple of properties, Delphi likewise 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 broadening the TTreeNode.Add it a string property MyProperty.Handle the OnCreateNodeClass for the tree view to indicate 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 rendition 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.