Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the component a popup menu click originated from

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?

like image 764
Ralph M. Rickenbach Avatar asked Mar 24 '10 06:03

Ralph M. Rickenbach


People also ask

Where is pop up menu?

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.

What is popup menu in Android?

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.

Which of the following classes is used to create pop up menu?

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.


2 Answers

Did you mean PopupMenu1.PopupComponent ?

like image 160
SimaWB Avatar answered Oct 31 '22 22:10

SimaWB


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; 
like image 27
Schneider Infosystems Ltd Avatar answered Oct 31 '22 23:10

Schneider Infosystems Ltd