PopUpMenu managing a child Menuitem

I have a PopUpMenu on TTreeView
and I have set it with a standard list of items before run time
I want to manage a constantly changing list according to the selected TreeView item at the time - this list looks better if its a child
I can create a MenuItem - but how do I make a child MenuItem?

1 Like

In the menu designer, right click on the menu item where you want to create a submenu, then click “new sub menu” or hit CTRL + right arrow

If you want to do it in code it’s a little more complicated - the description is here: Vcl.Menus.NewSubMenu - RAD Studio API Documentation

I can use the template ok
I want to do it in code
I could make a list of child menuItems and the remove visibility I guess until I need them
to be visible but then I have to find them in code some how

may be use the TAG and give them a number to identify them
or is their a better way

I want a parent instruction to find the child under the parent !!!
TreeView nodes do that so why is menuItems not offering the same thing?

You need to look at the menu’s events - Vcl.Menus.TPopupMenu.OnPopup - RAD Studio API Documentation - this allows you to populate the items or enable/disable them as necessary.

Here’s some example code which shows you what to do: OnPopup (Delphi) - RAD Studio Code Examples

Also, I assume you’re iterating the menu’s items property and then checking that the items.count property of each item is either 0 (no children) or is > 0 in which case you iterate that collection of items too. You can use the parent property of menu items to work out which one it belongs to if it’s not otherwise determinate.

My use is a bit like listing a file name list
The problem is my thinking on this matter
I have been thinking and always like to think
Get item child count
then look/update at each item by number as I like
It is freedom of flexibility of my code to identify nodes in list order

ok because I don’t have node-child-count
use TreeView.Items.Count
make a for… do loop through all nodes
If a node has a parent of my node to hold child’s Up Date, delete and then add nodes If needed

Or do I
While Node.getFirstChild <> nil do Node.getFirstChild.Free;
Then build my full child node list under my node to hold child’s

What I’m saying is make a work around with No node child count to work from
and no node.item[No]
I’m sure this Delphi thinking is a through back from some where

this is not allowed
While ParentNode.getFirstChild <> nil do ParentNode.getFirstChild.Free;

Don’t use

ParentNode.getFirstChild.Free

use

TreeView.Items.Delete

1 Like