Search code examples
delphigridfiremonkeyvclpopupmenu

Get the calling component of TPopupMenu


I have a TStringGrid, that has a TPopupMenu connected. By clicking one event of the popup menu, I would like to get the calling component. Is that possible?

Background: It is a bigger project, every form has a "BasicForm" I can inherited from. So I would like to provide a "default popup menu" for grids that have stuff like Copy, Select, and so on in it. In the inherited form I only match the grid (if exists) with that popup and I'm done.


Solution

  • Seems you are looking for the PopupComponent property of TPopupMenu: Vcl.Menus.TPopupMenu.PopupComponent

    Indicates the component that last displayed the popup menu in response to a right mouse click.

    Read PopupComponent to determine which control is currently using the popup menu. In applications where multiple controls share the same pop-up menu, use PopupComponent to determine which of them displayed the menu.

    Set PopupComponent to associate a control with the menu before calling the Popup method programmatically to bring up the pop-up menu.