Note that there are some explanatory texts on larger screens.

plurals
  1. POAdvice on setting up new TreeView Data Type
    text
    copied!<p>I would like some advice and or tips on how to go about setting up a new Object Class for a TreeView using the TreeView's Node.Data property.</p> <p>I know how to create a basic Object type that can write/read from the .Data property, I do something like this:</p> <pre><code>type TMyData = class(TComponent) private FString1: String; FString2: String; FInteger1: Integer; published property String1: String read FString1 write FString1; property String2: String read FString2 write FString2; property Integer1: Integer read FInteger1 write FInteger1; end; </code></pre> <p><strong>To write a value to one of the properties Node.Data property:</strong></p> <pre><code>TMyData(TreeView1.Selected.Data).String1:= 'save this String'; </code></pre> <p><strong>To read a value:</strong></p> <pre><code>ShowMessage(TMyData(TreeView1.Selected.Data).String1); </code></pre> <p>Thats a pretty basic example of assigning Data to a Tree Node, Now this is where I need the help and advice, tips etc...</p> <p>From my example above, you can easily read/write standard properties such as String, Integer, Boolean etc. What about including and reading/writing to and from say a TListBox or TListView?</p> <p>Instead of writing standard data to a Tree Node, how about adding items to that TListView and writing the contents of that TListView to the TreeView Node.</p> <p>What if when clicking on one of the Tree Nodes, instead of returning a string, it could populate that TListView with Items and Images that were saved to earlier.</p> <p><strong>(1)</strong> This is the main form where you can add the Nodes to the TreeView. I actually use a more enhanced function to add to my TreeView, like so:</p> <pre><code>function AddMyDataNode(ATreeView: TTreeView; NodeName: String; NodeImage: Integer; String1, String2: String; Integer1: Integer; SelectNode: Boolean): TTreeNode; var Obj: TMyData; Node: TTreeNode; begin Result:= nil; Obj:= TMyData.Create(nil); try Obj.String1:= String1; Obj.String2:= String2; Obj.Integer1:= Integer1; Node:= ATreeView.Items.AddObject(ATreeView.Selected, NodeName, Obj); Node.ImageIndex:= NodeImage; Node.SelectedIndex:= NodeImage; Result:= Node; if SelectNode then Node.Selected:= True; ATreeView.SetFocus; except on E: Exception do ShowMessage('Could not add MyData Node: ' + E.Message); end; end; </code></pre> <p>Editing a Node will show another form called the Data Form...:</p> <p><strong>(2)</strong> This Data Form is where the data from the Node on the Main Form is read/written. With an addition of a TListView. The ListView should also be read/saved with the standard properties too.</p> <p>Adding/Editing a ListView item may include other standard properties, such as:</p> <p><strong>(3)</strong> The values on this form are saved into the ListView data.</p> <p>So in a nutshell:</p> <ul> <li>The TreeView Node.Data stores standard properties and also a TListView.</li> <li>This Data is show on another form called Data Form.</li> <li>The ListView on the Data Form also has data.</li> <li>Editing the ListView on the Data Form will show an additional Form with standard properties.</li> </ul> <p>I would like to know how I could best approach this, what tips could you provide, what is the easiest way to achieve something like this etc?</p> <p>Writing/Reading to and from the ListView is easily implemented I imagine in that it can be done by accessing the <code>ListView Items.Item[x].Data</code> property. Getting the ListView Data to store with the TreeView is the problem, I don't know how I could implement this type of behaviour.</p> <p>I would like to know advice on things like how I could define the Types etc.</p> <p>I look forward to hearing your ideas on this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload