Reputation: 11
I am writing a class that needs to validate a string as an existing menuItem. Ideally, I would need something similar to MenuItemDisplayStr(), but I need it to use that function at runtime as opposed to compile time. Is there something similar that can check a string if it is a menuItem?
Thank you for the help!
Upvotes: 1
Views: 689
Reputation: 480
You will have to iterate the AOT and compare the string to the menu items.
This code is adapted from the example provided here: https://blogs.msdn.microsoft.com/dsiebold/2010/08/13/use-x-to-loop-through-the-aot/
#AOT
//These are the macros for the paths found in #AOT.
//Don't use macros in practice. It's a bad habit.
//#define.MenuItemsDisplayPath('\\Menu Items\\Display')
//#define.MenuItemsOutputPath('\\Menu Items\\Output')
//#define.MenuItemsActionPath('\\Menu Items\\Action')
TreeNode menuItemParentNode;
//str menuItemName = "derp";//output: "derp is not a valid menu item"
str menuItemName = "ActivitiesMain";//output: "ActivitiesMain is a valid menu item"
//Only checking display here, you would need another level of
//nodes to do output and actions.
menuItemParentNode = TreeNode::findNode(#MenuItemsDisplayPath);
if (menuItemParentNode.AOTfindChild(menuItemName))
info(strFmt("%1 is a valid menu item", menuItemName));
else
info(strFmt("%1 is not a valid menu item", menuItemName));
Upvotes: 2