Recent

Author Topic: [SOLVED] TrayIcon - Does not refresh popup menu after removing menuitems  (Read 2929 times)

Hansaplast

  • Hero Member
  • *****
  • Posts: 674
  • Tweaking4All.com
    • Tweaking4All

When removing items from a TrayIcon PopupMenu, these items will not disappear (visually) from the menu. When clicking on such a removed item, the application crashes so I assume the TMenuItem object has been removed/destroyed correctly, but there was no visual update of the popup menu.


When just updating a caption, this does refresh just fine.
I did report this as a bug, maybe others ran into this issue as well... any workarounds/tricks are most welcome.



Attached a simple test project:


At start, the menu has one "fixed" item (caption=This Item Stays).


Click "Add Menu Item" adds dynamically a TMenuItem with caption 'Test Menu Item' and Tag=-1 (so we can identify which ones to remove later on).


Click TrayIcon and you'll see both MenuItems correctly - so adding MenuItems is not a problem.


Click "Remove Dynamic MenuItems" to remove the newly added MenuItem.
Click TrayIcon again: the menuitem is still visible.
Clicking the MenuItem = crash (suggesting the TMenuItem object is gone indeed).


Under Linux (GTK2) and Windows this works perfectly fine. Not under Cocoa though.


I've tested a silly "TrayIcon1.Hide, make changes to the menu, and TrayIcon1.Show" trick, but in Cocoa that actually generates additional TrayIcons for each time this is done (eg. "Hide" doesn't seem to work, and "Show" only creates and additional icon in the menubar).


The TrayIcon1.InternalUpdate trick, used with Carbon, doesn't seem to do anything under Cocoa.


Note:
For testing I've added a button to change the caption of the dynamically added MenuItems (Add 'x' in front of dynamic MenuItems). This does work correctly, obviously, removed menuItems still remain visible, but the caption of those will naturally not be updated.
« Last Edit: December 09, 2018, 04:48:03 pm by Hansaplast »

Hansaplast

  • Hero Member
  • *****
  • Posts: 674
  • Tweaking4All.com
    • Tweaking4All
Re: TrayIcon - Does not refresh popup menu after removing menuitems
« Reply #1 on: December 04, 2018, 02:34:51 pm »
Could this be related to the fact that Freeing or Destroying the TrayIcon has no effect?
After a TrayIcon1.Free or TrayIcon1.Destroy, the TrayIcon simple remains visible and fully functional and is not being freed.


Freeing the popup menu (TrayIcon1.PopUpMenu:=nil; PopupMenu1.Free;) the menu still remains visible - clicking an item then produces an access violation.

Hansaplast

  • Hero Member
  • *****
  • Posts: 674
  • Tweaking4All.com
    • Tweaking4All
[SOLVED] TrayIcon - Does not refresh popup menu after removing menuitems
« Reply #2 on: December 09, 2018, 04:47:52 pm »
Dmitry solved this in SVN  ;)

 

TinyPortal © 2005-2018