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.