OnPopup (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

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.

Code

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;

Uses