TTMSFMXTreeView Parse

Hello folks;  Years since I programmed anything serious and I've renewed my Delphi subscription. I am trying to first modernize an application I wrote for keeping track of my own code. This being written as cross-platform, and the controls are FireMonkey.

I use a TTMSFMXTreeView to display data organized into three hierarchical levels.
I have a search interface that selects code snippets that match supplied criteria into a tabular view; then when the user selects from the grid, the treeview is synchronized so the selected snippet is the hot tree node, and the underlying data is displayed in separate memo components.

Only the third (child-most) level needs be searched, and what I have done is put an ID into node.Text[1] which is not a displayed column. I am hitting a wall attempting to iterate/parse/search the treeview.

Can I ask for a leg up please?

Thanks in advance folks! I'll try to reciprocate!


You can use the following code to search for nodes with ID's on the third level. Please note that it is not necessary to add an additional column for storing the ID, as you can store the ID in the DataString property of a node:

  n, nc, ncc: TTMSFMXTreeViewNode;
  n := TMSFMXTreeView1.GetFirstRootNode;
  while Assigned(n) do
    nc := n.GetFirstChild;
    while Assigned(nc) do
      ncc := nc.GetFirstChild;
      while Assigned(ncc) do
        //ncc.DataString; --> ID
        ncc := ncc.GetNextSibling;
      nc := nc.GetNextSibling;
    n := n.GetNextSibling;

Kind Regards, 

Thank you for the reply.  I am guilty of not being specific enough in my question.I have actually figured out how to transit the tree, but this is invisible to the user. It does not SELECT the node in question, and make it active. I need to programmatically select the appropriate node. I cannot figure out how to do so. This act of selection will cause a nice trickle down, populating controls and so forth.

I've amended the code given to open the tree in the correct area, but the target node is not especially pointed out...

        if ncc.Text[1] = '33' then
          bBreak := True;
          //ShowMessage('Found: '+ncc.Text[0] );
          SearchTree.ScrollToNode(ncc); {tree now open to this node, but it is not selected yet.}
I've put in a literal (33) rather than post the search process that derives the value we're searching for.I'm sure this is a very simple thing, buy I've wasted hours on it!

To select a node, you can use


It's actually unclear exactly what you want to achieve, does the code break after ncc.Text[1] = '33'?

Kind Regards, 

Wow, I knew that would be simple! Why I failed to find that I can't say. That should fix me up. What follows is an explanation of what I'm up to, if you're curious. I have had this app running for years, but I'm updating it and moving it into cross-platform with Delphi Seattle.

Yes, the code breaks after the node is located and focused. '33' is a literal I've substituted for a value passed by another procedure (the Search dialog).
The tree is a hierarchy of: (programming) Language, Area (of interest), and Name (of snippet). As one traverses the tree, clicking the Name of a snippet populates two memos: Notes and Code.

One can manually traverse the tree to remind themselves of, say, the constants associated with a MessageDlg. Delphi>Form Unit Code>Message options

There is also a search facility which allows you to search within notes and code for phrases or key words. This dialog returns a table of hits. Clicking one of them jumps the user back to the tree page, with the target code snippet selected, and the associated Notes and Code populating the Memo controls.

This way one can very quickly cut and paste from these memos into active code. I have a crap memory, so this speeds up my work tremendously. It also acts as a hall of fame for great segments that I've toiled through, which can be used in other contexts.

Thanks for your help. If you're interested I will send the completed project to you.It would be very helpful for parsing code snippets you folks have created in what I consider a very user friendly format.

That sounds very cool, a kind of code snippet manager if I understand well.
I guess many other users might be interested in this tool too.