Creates and initializes a main menu.
function NewMenu(Owner: TComponent; const AName: string; const Items: array of TMenuItem): TMainMenu;
TMainMenu NewMenu(TComponent * Owner, const AnsiString AName, const array of TMenuItem Items);
Call NewMenu to create and initialize a main menu programmatically. NewMenu returns the TMainMenu component that represents the menu.
The Owner parameter specifies the component that is responsible for freeing the menu (typically the form).
The AName parameter specifies the name of the menu, which is used to refer to it in code.
The Items parameter is an array of menu items that make up the top level menu items. To create the menu items for the Items parameter, use the NewItem function.
C++ Examples:
/* This code displays a new menu named MyMenu when the user clicks the button. MyOnExecute must be included in the definition of the TForm1 class. Click on the menu item or type "Ctrl+N" to execute MyOnExecute. */ void __fastcall TForm1::Button1Click(TObject *Sender) { TMenuItem *Item1 = NewItem("New item", TextToShortCut("Ctrl+N"), false, true, MyOnExecute, 0, "Item1"); Menu = NewMenu(this, "MyMenu", &Item1, 0); } void __fastcall TForm1::MyOnExecute(TObject *Sender) { MessageDlg("Item1 has been executed.", mtInformation, TMsgDlgButtons() << mbOK, 0); }
Delphi Examples:
{ This code displays a new menu named MyMenu when the user clicks the button. MyOnExecute must be included in the definition of the TForm1 class. } procedure TForm1.Button1Click(Sender: TObject); begin Menu := NewMenu(Self, 'MyMenu', [NewItem('New item', TextToShortCut('Ctrl+N'), False, True, MyOnExecute, 0, 'Item1')]); end; procedure TForm1.MyOnExecute(Sender: TObject); begin MessageDlg('Item1 has been executed.', mtInformation, [mbOK], 0); end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|