RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
Menus.TextToShortCut Function

Creates a menu shortcut from a text string.

Pascal
function TextToShortCut(Text: string): TShortCut;
C++
TShortCut TextToShortCut(AnsiString Text);

Call TextToShortCut to create a menu shortcut from a descriptive string. For example, an application can allow users to specify the value of a shortcut in an edit box control, and then call TextToShortCut to create a menu shortcut for the value entered by the user.

Note: TextToShortCut executes slowly. When possible, use the ShortCut function to create a menu shortcut instead.
 

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!