Dear Sirs,
TMS Web Core 1.6.2.0
RAD Studio Sydney (Delphi 10.4 Version 27.0.38860.1461)
Please see attached project WebCoreBugMainMenu.zip (307.1 KB)
Click button "Run" to expose the problem.
MenuItem.Insert
When we try to insert a menu item at a specific index we get this error:
Uncaught TypeError: Cannot read property 'UpdateElement' of null | TypeError: Cannot read property 'UpdateElement' of null at Object.Insert$1
The problem is that "Parent" is not assigned when item is inserted.
Example code:
LIndex := 2;
LMenuItemNew := TMenuItem.Create(nil);
LMenuItemNew.Name := 'mi1';
LMenuItemNew.Tag := 1;
LMenuItemNew.Caption := '1';
LMenuItemNew.Enabled := True;
LParentMenuItem.Insert(LIndex, LMenuItemNew);
Other variations of this example also fail with same problem:
LIndex := 2;
LMenuItemNew := TMenuItem.Create(LParentMenuItem);
LMenuItemNew.Name := 'mi1';
LMenuItemNew.Tag := 1;
LMenuItemNew.Caption := '1';
LMenuItemNew.Enabled := True;
LParentMenuItem.Insert(LIndex, LMenuItemNew);
Only this example works but we can not change menu item index:
LMenuItemNew := TMenuItem.Create(nil);
LMenuItemNew.Name := 'mi1';
LMenuItemNew.Tag := 1;
LMenuItemNew.Caption := '1';
LMenuItemNew.Enabled := True;
LMenuItemNew.SetParentComponent(LParentMenuItem);
MenuItem remove
Current workaround for item removal is to find menu item (LMenuItem) and run:
LParentMenuItem.RemoveComponent(LMenuItem); // removes item
LMenuItem.Free; //removes visual (html/dom) item
Not yet supported calls would be prefered:
TMenuItem.Delete(Index: Integer); //[Error] uMain.pas(58): identifier not found "Delete"
TMenuItem.Remove(Item: TMenuItem); // [Error] uMain.pas(57): Can't access private member Remove
Kind regards