2004. december 7., kedd

How to get the PopupPoint of a TPopupMenu


Problem/Question/Abstract:

I have a popup menu assigned to a TListView. I'm trying to get the ListItem where the right click occured. I can not get the coords where the popup click happened due to the fact that PopupMenu.PopupPoint is protected.

Answer:

type
  TCrackPopupMenu = class(TPopupMenu)
  end;

procedure TForm1.PopupMenu1Popup(Sender: TObject);
var
  pt: TPoint;
begin
  pt := TCrackPopupMenu(PopupMenu1).PopupPoint;
  Label1.Caption := Format('Popped up at: X = %d, Y = %d', [pt.x, pt.y]);
end;

By the way, PopupPoint returns screen coordinates.

Nincsenek megjegyzések:

Megjegyzés küldése