2

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!!!

1 Answer 1

4

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.