1

我正在编写一个需要将字符串验证为现有菜单项的类。理想情况下,我需要类似于 MenuItemDisplayStr() 的东西,但我需要它在运行时而不是编译时使用该函数。如果它是菜单项,是否有类似的东西可以检查字符串?

感谢您的帮助!

4

1 回答 1

2

您将不得不迭代 AOT 并将字符串与菜单项进行比较。

此代码改编自此处提供的示例: 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));
于 2016-04-21T20:37:32.177 回答