maxfax
maxfax

Reputation: 4315

Delphi: PopUpMenu

There is a list View + a PopUpMenu. I need that the PopUpMenu appears when items are present. The menu must not appears when 0 items.

Is this approximate code appropriate (can be used as a basis)?

procedure TForm1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var P: TPoint;
begin
  P:=GetClientOrigin;
  if Button = mbRight then
     PopupMenu1.Popup(X+P.X+StringGrid1.Left, Y+P.Y+StringGrid1.Top);
end;

Are there other ways?

Thanks!!!

Upvotes: 2

Views: 2026

Answers (1)

David Heffernan
David Heffernan

Reputation: 613442

Firstly, don't do anything on a mouse event because the popup menu can be invoked from the keyboard.

The best way to do this, in my view, is to handle the OnPopup event. If you want the menu not to appear call Abort.

procedure TForm1.PopupMenu1Popup(Sender: TObject);
begin
  if SomeCondition then
    Abort;
end;

Upvotes: 4

Related Questions