RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TPopupMenu.OnPopup Event

Occurs just before the pop-up menu appears.

Pascal
property OnPopup: TNotifyEvent;
C++
__property TNotifyEvent OnPopup;

Write an OnPopup event handler to take specific action just before the pop-up menu appears. For example, use an OnPopup event handler to set the Checked, Enabled, or Visible property of individual items in the menu so that they are appropriate to the PopupComponent.  

C++ Examples: 

 

/*
The following code enables the Copy item from the pop-up
menu if the edit control has a nonempty selection.
Note: A portion of the edit control text must be highlighted.
*/
void __fastcall TForm1::PopupMenu1Popup(TObject *Sender)
{
  Copy1->Enabled = (Edit1->SelLength > 0);
}

void __fastcall TForm1::Copy1Click(TObject *Sender)
{
    ListBox1->Items->Add("'Copy' menu");
}

void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
          int X, int Y)
{
  PopupMenu1->Popup(X, Y);
}

 

Delphi Examples: 

{
The following code enables the Copy item from the pop-up
menu if the edit control has a nonempty selection.
Note: A portion of the edit control text must be highlighted.
}
procedure TForm1.PopupMenu1Popup(Sender: TObject);
begin
  Copy1.Enabled := Edit1.SelLength > 0;
end;

procedure TForm1.Copy1Click(Sender: TObject);
begin
    ListBox1.Items.Add('"Copy" menu');
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  PopupMenu1.Popup(Left + X, Top + Y);
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!