There is no difference between submenus in standard menus or context (popup) menus: If a menu item has a submenu attached, then its OnClick
event will fire just before the submenu is shown (note that you don't need to click for it to show up), and in that event handler you can modify the submenu (either set properties of existing items, or add new items / delete existing items).
Some demo code about dynamically adding and removing items:
procedure TForm1.FormCreate(Sender: TObject);
var
Popup: TPopupMenu;
Item, SubItem: TMenuItem;
begin
Popup := TPopupMenu.Create(Self);
PopupMenu := Popup;
Item := TMenuItem.Create(Popup);
Item.Caption := 'Test submenu';
Item.OnClick := PopupClick;
Popup.Items.Add(Item);
SubItem := TMenuItem.Create(Item);
SubItem.Caption := 'dummy';
Item.Add(SubItem);
end;
procedure TForm1.PopupClick(Sender: TObject);
var
SubmenuItem, Item: TMenuItem;
begin
SubmenuItem := Sender as TMenuItem;
// delete old items (leave at least one to keep the submenu)
while SubmenuItem.Count > 1 do
SubmenuItem.Items[SubmenuItem.Count - 1].Free;
// create new items
while SubmenuItem.Count < 3 do begin
Item := TMenuItem.Create(SubmenuItem);
Item.Caption := Format('new item created %d', [GetTickCount]);
SubmenuItem.Add(Item);
end;
end;