1 1 Vote

Delphi/Lazarus: Which Control has called a PopUp Menu? Sender of TPopupMenu?

Question by Guest | 22/09/2013 at 19:47

I am using the same PopUpMenu for various controls (ListView and ListBox) in my project.

So far, calling the pop-up menu works quite well, but there are problems when it is up to determine the Sender/Caller of the menu. So, for example, I want to know from which of the ListViews the PopUp Menu was invoked.

In addition, my first try was to take the variable "Sender" from the procedure "OnPopUp" but strangely enough the Sender is always the same, so I cannot use this to reach my goal.

Another idea was to store in a variable on which control was clicked last. Of course, that will work, but I think that is too much complicated! There must be an easier way to find out from where the PopUp was called, right?



Show Profile | Message
2Best Answer
2 Votes

Yes, there is a much easier way. Namely, the property PopupComponent provided by the TPopupMenu itself. In this property, it is always saved, which component has called the PopUp for the last time.

Here's an example:

if PopupMenu1.PopupComponent=ListView1 then begin
   ShowMessage('Called from ListView1');

if PopupMenu1.PopupComponent=ListView2 then begin
   ShowMessage('Called from ListView2');

if PopupMenu1.PopupComponent is TListView then begin
   ShowMessage('Called from a ListView');

In the first examples, we are asking directly whether it has been called by ListView1 or ListView2. The third example generally reacts when the popup is called by a ListView - so it reacts to both, ListView1 as well as ListView2. 
24/09/2013 at 18:41

ReplyPositive Negative
00 Votes


   dbGridX : TDBGrid;


   if not (FindComponent(PopupMenu1.PopupComponent.Name) is TDBGrid) then Exit;

   dbGridX := TDBGrid(FindComponent(PopupMenu1.PopupComponent.Name));


28/07/2019 at 16:53

ReplyPositive Negative

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.


Ask your own question or write your own articles on askingbox.com. How to do.