RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
Menus.ShortCut Function

Creates a menu shortcut for a specified key combination.

Pascal
function ShortCut(Key: Word; Shift: TShiftState): TShortCut;
C++
TShortCut ShortCut(Word Key, TShiftState Shift);

Menus

Call ShortCut to create a menu shortcut at runtime.  

Specify a Key value using a virtual key code (Menus version) or Qt key code (QMenus version). 

Specify the values for the Shift, Control, and Alt keys by using a set of type TShiftState. For example, to specify the Shift key, use the set [ssShift]. To specify a Shift and Ctrl key combination, use the set [ssShift, ssCtrl]. 

Assign the value returned by ShortCut as the value of the ShortCut property of a menu item.

Note: TextToShortCut can also create a shortcut. TextToShortCut converts a string to a shortcut, so it can be used to let the user specify the shortcut. However, TextToShortCut executes much more slowly than ShortCut. Use ShortCut whenever possible.
 

Delphi Examples: 

 

{
This line creates a shortcut, Ctrl+O, at run time and
assigns it to the Open command on a File menu.
}
procedure TForm1.FormCreate(Sender: TObject);
begin
  OpenCommand.ShortCut := Menus.ShortCut(Word('O'), [ssCtrl]);
end;

procedure TForm1.OpenCommandClick(Sender: TObject);
begin
  MessageDlg('The Open command has been selected.', mtInformation, [mbOk], 0);
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!