Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/FireMonkey/Components    [ Add a report in this area ]  
Report #:  106905   Status: Open
TMenuItem.InsertObject does not work
Project:  Delphi Build #:  16.0.4504.48759
Version:    16.4 Submitted By:   etax DWS
Report Type:  Basic functionality failure Date Reported:  7/5/2012 12:14:29 AM
Severity:    Serious / Highly visible problem Last Updated: 7/5/2012 1:17:11 AM
Platform:    All platforms Internal Tracking #:   29648
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: (1 Total Rating)
5.00 out of 5
Total Votes: None
Description
TMenuItem.InsertObject does not insert a menu item, although it looks like the menu item has been included in the list.

----------
procedure TForm3.Button1Click(Sender: TObject);
var
  newmenu : TMenuItem;
begin
  newmenu := TMenuItem.Create(MainMenu1);
  newmenu.Name := 'test';
  newmenu.Text := 'test';

  MenuItem1.InsertObject(0, newmenu);
end;
----------

AddObject works, but I need to be able to insert into specific location.  Any ideas?
Steps to Reproduce:
1. Create a FireMonkey HD form with a TMainMenu and child TMenuItem.
2. Programmatically create a new TMenuItem and insert it into any of the existing TMenuItems.
3. Newly created TMenuItem does not appear, although it seems like object instance has been created and added to the parent's list.

I've attached sample application.
Workarounds
None
Attachment
Menus InsertObject issue.zip
Comments

Tomohiro Takahashi at 7/5/2012 12:48:10 AM -
Does your issue occur on both Windows and MacOS X?

etax DWS at 7/5/2012 12:52:09 AM -
Yes, issue happens for both Mac and Windows (7).

Tomohiro Takahashi at 7/5/2012 7:03:16 AM -
This report was opened with valid Internal Tracking Number.
Thanks.

Remy Lebeau (TeamB) at 7/10/2012 7:32:44 PM -
TMenuItem does not have its own InsertObject() method, it inherits one from TFmxObject instead.  TMenuItem is not the immediate container of the child menu items.  TMenuItem has an internal TContent object that is the actual container.  Calling TMenuItem.InsertObject() inserts the new menu item alongside the TContent object instead of inside of it.  TMenuItem needs to override the virtual TFmxObject.InsertObjecct() method (much like the TMenuItem.AddObject() method does).

In the meantime, a workaround is to do this instead:

uses
  Fmx.Platform;

MenuItem1.Children[0].InsertObject(0, newmenu);
if IsHandleValid(MenuItem1.Handle) then
  Platform.UpdateMenuItem(MenuItem1);

Server Response from: ETNACODE01