Forum Discussion

Colin_McCrae's avatar
Colin_McCrae
Community Hero
10 years ago
Solved

Delphi popup menu?

Hi

 

I'm having a bit of bother with popup menu objects which are spawned by right clicking on TTreeView menu object options.

 

The popup menu objects are transient. As soon as you move elsewhere on the screen, they vanish, so getting much in the way of info about properties/methods on them is kind of tricky.

 

I can make a selection from them no problem. Right click the item in the TTreeView menu (which causes the popup menu to be generated), then "PopUpMenu" is a property of it (it being the TTreeView - I never act on the popup menu as an object in it's own right) 0and you can select from the popup using pipe separators to as many levels deep as you need. In much the same way as you select items in the TTreeView.

 

However, I'm struggling to find any way of doing anything other than select items as I can't spy the object to get any further detail on what, if anything, I can do with it.

 

CTRL+SHIFT+A in object spy does allow me to capture it. But it then immediately disappears and doesn't leave me with any useful information in the object spy details.

 

I've looked up the object documentation and tried a few of the properties and methods mentioned on it, but most don't work or return a dummy context menu rather than anything useful

 

It's these popup objects it's generating: http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/Menus_TPopupMenu.html

 

Debug build options are switched on for the Delphi module so I have access to all the underlying methods and properties.

 

Any suggestions on how to do stuff like validating that a specific menu option exists within the menu once it's brought up? It's things along those lines I'd like to do rather than just driving it blind and hoping the selections I give it (data driven test functions) are valid .....

 

Thanks in advance.

 

 

6 Replies

  • Update ...

     

    Found this thread:

     

    http://community.smartbear.com/t5/Getting-Started-with/Work-with-Windows-PopupMenu-in-Windows-7-and-XP/td-p/55128/page/2

     

    ... which gets me so far. I can get a True/False if I put the text object capture between the right click on the TTreeView menu, and the selection of the PopUpMenu option.

     

    BUT!

     

    This only allows me to validate the first level of menu options. Some of the popup menus go several levels deep. This doesn't seem to help me here for two reasons:

     

    1. When initially triggering the popup menu with a right click on the tree view, it only opens to the first level. Subsequent levels only open by hovering over menu options.

    2. If I open it several levels deep using the CTRL+SHIFT+A object spy method, I do get a text object back. But it only shows the final selection. It doesn't show the full menu path to get there.

     

    Any further suggestions welcome ....

    • AlexKaras's avatar
      AlexKaras
      Icon for Champion Level 3 rankChampion Level 3

      Hi Colin,

       

      Just a quick idea: as you can get the text of the currently selected menu item, what if you try to 'manually' navigate through the menu?

      I.e. something like this:

      -- Open the menu using right-click;

      -- Search for the first item in your menu path in the opened menu;

      -- If the menu item was found, hover mouse over it (via the .HoverMouse() method);

      -- Search for the subsequent sub-menu window;

      -- If the sub-menu window was found, search for the second item from the menu path, hover the mouse over it and so on until all path is verified.

      • Colin_McCrae's avatar
        Colin_McCrae
        Community Hero

        Hi Alex

         

        Thanks for the input.

         

        Thats pretty much what I've been trying to do. And it finds the first level menu item no problem. But, so far, it always fails to find the second one. No idea why. The search criteria are correct (object type of MenuItem and it's caption). I have "sys.refresh" in all the relevant places place. I've tried adding delays. But they're never found.

         

        Which is odd. As the object info I get from spying them implies they should be.

         

        (I've also tried recording using them and the recorded object fit in with the object spy info .... most confusing)

         

        I'll keep prodding it and update if I have a eureka moment!