TListBox is designed to display 3-10 pictures on the form. You click on the Add button, a TListBoxItem is created with a TImageViewer. The TImageViewer HitTest is disabled. TPopupMenu is tied to both TListBoxItem and TListBox. By long tap should pop up. The Long tap event is triggered, but the menu is not displayed.

I create ListBoxItem

procedure TfmEditObject.AddPhoto(Image: TBitmap); Var item: TListBoxItem; imageV: TImageViewer; begin item := TListBoxItem.Create(lbPhotos); item.parent := lbPhotos; item.text := ''; item.Width := lbPhotos.Width; item.PopupMenu := PopupMenu1; imageV := TImageViewer.Create(lbPhotos); imageV.HitTest := False; imageV.Parent := item; imageV.Align := TAlignLayout.Client; imageV.Bitmap.Assign(image); item.SetFocus; end; 

The OnGesture event on the ListBox is triggered and reaches the line with the menu display, but the menu does not pop up

 procedure TfmEditObject.lbPhotosGesture(Sender: TObject; const EventInfo: TGestureEventInfo; var Handled: Boolean); var c: IControl; ListBox: TListBox; lbxPoint: TPointF; ListBoxItem: TListBoxItem; begin if EventInfo.GestureID = igiLongTap then if (sender is TListBox) and assigned(TListBox(sender).Selected) then begin c := ObjectAtPoint(EventInfo.Location); if Assigned(c) then if Assigned(c.GetObject) then if c.GetObject is TListBox then begin ListBox := TListBox(c.GetObject); lbxPoint := ListBox.AbsoluteToLocal(EventInfo.Location); ListBoxItem := ListBox.ItemByPoint(lbxPoint.X, lbxPoint.Y); if Assigned(ListBoxItem) then begin PopupMenu1.Popup(lbxPoint.X, lbxPoint.Y); ShowMessage(FloatToStr(lbxPoint.X) + ':' + FloatToStr(lbxPoint.Y)); end; Handled := True; end; end; end; 

A ShowMessage with coordinates pops up. What's wrong? How to show the context menu correctly? Delphi 10.1 Upd 2

  • ShowMessage doesn’t close the menu with its appearance and interception of focus? .. Well, plus, I'm not sure exactly about FMX, but in VCL PopupMenu.Popup () requires global coordinates, not local ones for the element. - Alekcvp
  • And popupmenu in Android generally able to appear? - Akella225
  • I have no idea and in the question there is not a word about the android. - Alekcvp
  • "ShowMessage doesn’t close the menu by its appearance and interception of focus?" Not. Without ShowMessage also does not pop up. - Akella225

1 answer 1

Tinkering with TListBox:

https://community.embarcadero.com/blogs/entry/creating-an-overflow-menu-on-android-463