unit OnPopup;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Menus;

type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;
    Hereis1: TMenuItem;
    your1: TMenuItem;
    popup1: TMenuItem;
    menu1: TMenuItem;
    ListBox1: TListBox;
    Copy1: TMenuItem;
    Edit1: TEdit;
    procedure Hereis1Click(Sender: TObject);
    procedure your1Click(Sender: TObject);
    procedure popup1Click(Sender: TObject);
    procedure menu1Click(Sender: TObject);
    procedure Copy1Click(Sender: TObject);
    procedure PopupMenu1Popup(Sender: TObject);
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// BeginExample: OnPopup
// Event: Menus.TPopupMenu.OnPopup

// BeginCode
{
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;
// EndCode
// EndExample: OnPopup

procedure TForm1.Hereis1Click(Sender: TObject);
begin
    ListBox1.Items.Add('"Here is" popup menu');
end;

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

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

procedure TForm1.your1Click(Sender: TObject);
begin
    ListBox1.Items.Add('"your" popup menu');
end;

end.
