Forum Discussion

Colin_McCrae's avatar
Colin_McCrae
Community Hero
9 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.

 

 

  • Colin_McCrae's avatar
    Colin_McCrae
    9 years ago

    ** FINAL UPDATE **

     

    OK. I have it working now.

     

    Was not able to use the index. Even with three levels of menu open (all of type "Popup") they all report an index of 1 and it always finds the first level container? No idea why. But thats what was happening.

     

    So, I ended up using the "Name" property. As each new level container is spawned, it's name appears to be dynamically generated based on the selection prior to it. With the first level always having the name "Context".

     

    So to find each level, I search for a container of type "Popup" with "Name" properties of:

     

    Level 1 - ["Popup"]("Context") - pre-populated

    Level 2 - ["Popup"]("Level 1 selection text") - Selection text based on the user input

    Level 3 - ["Popup"]("Level 2 selextion text") - Same as above ...

     

    And so on. For as few or many levels deep as requirted. (It's in a loop obviously) As it finds each new container, finding the MenuItem within that is simple. It hovers each one until the end and clicks on the final one if it gets through without any errors.

     

    The containers are all direct children of the top level process so it doesn't have to search too deep. Each container then only contains a handful of MenuItem object to search through. So the speed remains good.

     

    As each component is searched out and identified before it is used, I can validate as I go and and failed object searches will be picked up and generate the required error messages. (This is all data driven so needs to be robust in case people feed it garbage)

     

    Very convoluted way of getting there. But got there in the end.

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
      Champion 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!