RAD Studio VCL Reference
|
Inserts a menu item into a specified position in the Items array.
procedure Insert(Index: Integer; Item: TMenuItem);
__fastcall Insert(int Index, TMenuItem Item);
Use Insert to insert a new menu item to the dropdown menu for this menu item. If this menu item is the value of the Items property of a main menu or pop-up menu, Insert inserts an item into that menu. Specify the new menu item to add as the value of the Item parameter, and the position in the Items array as the value of the Index parameter.
C++ Examples:
/* This code inserts a menu item after the first item in a menu named FileMenu: */ void __fastcall TForm1::InsertMenuItemClick(TObject *Sender) { TMenuItem *NewItem = new TMenuItem(FileMenu); try { NewItem->Caption = "Form1"; FileMenu->Insert(1, NewItem); } catch (Exception &e) { delete NewItem; throw; } }
Delphi Examples:
{ This code inserts a menu item after the first item in a menu named FileMenu: } procedure TForm1.InsertMenuItemClick(Sender: TObject); var NewItem: TMenuItem; begin NewItem := TMenuItem.Create(FileMenu); try NewItem.Caption := 'Do this'; FileMenu.Insert(1, NewItem); except NewItem.Free; // Throw away the menu item if there is an error. raise; // reraise the exception end; // Don't free the menu item on success. Need it for the menu! end; // Free all the menu items that we have created dynamically. procedure TForm1.FormDestroy(Sender: TObject); var I : Integer; begin for I := FileMenu.Count - 1 downto 0 do // Index backwards because Count changes as you remove items. if FileMenu.Items[I].Name = '' then // Items created dynamically have not name. FileMenu.Items[I].Free; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|