Delphi/Lazarus: Which Control has called a PopUp Menu? Sender of TPopupMenu?
Question by Guest | 2013-09-22 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?
Related Topics
PHP: Sending an E-Mail
Tutorial | 0 Comments
Delphi/Lazarus: Select all with CTRL+A in ListView
Tip | 0 Comments
Lazarus: Match FormDropFiles with a specific ListView
Tutorial | 0 Comments
Delphi: Global Treatment of Errors (Exceptions)
Tutorial | 0 Comments
Delphi/Lazarus: How to set up a Link to a Website in an Application
Tutorial | 0 Comments
Delphi/Lazarus: Delete selected Items from ListBox using DEL-Key
Tip | 3 Comments
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.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
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:
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.
2013-09-24 at 18:41
var
dbGridX : TDBGrid;
begin
if not (FindComponent(PopupMenu1.PopupComponent.Name) is TDBGrid) then Exit;
dbGridX := TDBGrid(FindComponent(PopupMenu1.PopupComponent.Name));
...
end;
2019-07-28 at 16:53