Recent

Author Topic: demo: many controls sharing one TPopupMenu  (Read 2686 times)

kapibara

  • Hero Member
  • *****
  • Posts: 610
demo: many controls sharing one TPopupMenu
« on: April 21, 2014, 02:01:42 pm »
There were several similar controls on my form, and all needed a popup menu. But using one popupmenu for each control seemed too much of clutter. TPopupMenu has the PopupComponent property to help out here, I discovered:

Assign the calling control to PopupMenu.PopupComponent programmatically just before showing the popup and then call the appropriate method. Check the demo I made if you think this could be useful.
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: demo: many controls sharing one TPopupMenu
« Reply #1 on: April 21, 2014, 02:16:55 pm »
Nice, although you use left mouse button to show the pop-menu, it is unusual.

The same job can be done using OnContextPopup event which is triggered before the pop-menu is displayed. TSpeedButton, which you use in your demo, hasn't got this event published but I believe it's there, it only has to be assigned at run-time (via code).

Shared code for the event can look like this:
Code: [Select]
procedure TForm1.FormContextPopup(Sender: TObject; MousePos: TPoint; var Handled: Boolean);
begin
  pmShared.PopupComponent:=TComponent(Sender);
end;
It will assign to property PopupComponent the control which raises the pop-menu.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

kapibara

  • Hero Member
  • *****
  • Posts: 610
Re: demo: many controls sharing one TPopupMenu
« Reply #2 on: April 21, 2014, 09:11:20 pm »
Thanks, the SpeedButton doesn't seem to have any OnContextPopup though.

In my app the speedbutton serves as label and dropdown-button for a some comboboxes. Saves space. :)

Is there an advantage of using OnContextPopup? For fun I tried to use it with a TLabel, to mirror the behaviour with the speedbutton, but didnt get it to work at first try.

The attached demo shows how I use it with comboboxes.
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: demo: many controls sharing one TPopupMenu
« Reply #3 on: April 21, 2014, 09:38:15 pm »
Quote
Is there an advantage of using OnContextPopup?
I wouldn't say advantage but it's a more native approach.

Quote
... but didnt get it to work ...
You need to assign pop-menu to PopupMenu property and assign OnContextPopup event. Then right-mouse-button will trigger the event and show the pop-menu.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

 

TinyPortal © 2005-2018