Having a popup menu attached to several components on a form (buttons, but also things like TCharts), I would like to know which component was right clicked to start the popup menu in the first place.
The Sender parameter of the click method just points to the TMenuItem, its parent to the popup menu (or the parenting menu item).
How do I get the originating component?
Go to app > res > right-click > New > Android Resource Directory and give Directory name and Resource type as menu. Now, we will create a popup_menu file inside that menu resource directory. Go to app > res > menu > right-click > New > Menu Resource File and create a menu resource file and name it as popup_menu.
In android, Popup Menu displays a list of items in a modal popup window that is anchored to the view. The popup menu will appear below the view if there is a room or above the view in case if there is no space and it will be closed automatically when we touch outside of the popup.
CHOICE CLASS is used to create a pop-up list of items in java. Explanation: Choice class is part of Java Abstract Window Toolkit(AWT). The Choice class presents a pop- up menu for the user, the user may select an item from the popup menu.
Did you mean PopupMenu1.PopupComponent ?
You can get the caller component within the click event of the TMenuItem of a PopupMenu by
Caller := ((Sender as TMenuItem).GetParentMenu as TPopupMenu).PopupComponent;
An Example of a PopupMenu which is assigned to several list boxes and solves the export to file functionality:
procedure TForm1.mniExportFileClick(Sender: TObject);
var Caller: TObject;
begin
if SaveTextFileDialog1.Execute then
begin
Caller := ((Sender as TMenuItem).GetParentMenu as TPopupMenu).PopupComponent;
(Caller as TListBox).Items.
SaveToFile(SaveTextFileDialog1.FileName,
StandardEncodingFromName(
SaveTextFileDialog1.Encodings[SaveTextFileDialog1.EncodingIndex]));
end;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With