I was toying with TTrayIcon on a Mac and found that when you add items dynamically (at runtime) to the popupmenu of the trayicon, that changes are not made visible when you click the trayicon (placed on the Mac in the top Menu Bar). So far this seems "normal" as I have gotten no response if this should be this way or not.
No matter what you try: add/remove/change items, even destroy the entire popupmenu - it remains as was at startup of your application.
After a lot of fiddling I found a trick that makes it that changes are visible. Simply hide the trayicon, make your changes and show it again.
trayicon1.Hide;
// add/remove/modify popupmenu items
trayicon1.Show;
For those interested, this is how you add items to the menu:
...
var tmpMenuItem : TMenuItem;
...
tmpMenuItem := TMenuItem.Create(PopupMenu1);
tmpMenuItem.Caption:='new menu item';
// Optional:
// tmpMenuItem.Name := 'MyMenuItem'; // Give it a name so you can later "talk" to this item
// Optional, but pretty much required, otherwise the menu doesn't do anything when you click it
// tmpMenuItem.OnClick:=@MenuItem_Click; // so the click event is handled
...
PopupMenu1.Items.Add(tmpMenuItem); // insert at the beginning or at a given position
// PopupMenu1.Items.Insert(0,tmpMenuItem); // Alternative: insert at the beginning or at a given position
...
The procedure MenuItem_Click could be defined as:
...
procedure MenuItem_Click(Sender: TObject);
...
procedure TConnectMeNowForm.MenuItem_ServerShareClick(Sender: TObject);
var tmpMenuItem:TMenuItem;
begin
tmpMenuItem:=TMenuItem(Sender);
if tmpMenuItem='MyMenuItem' then ... // do something
...
end;