5

I just used the SecondaryShortCuts-Feature of Delphi's TAction. But Shortcuts are defined by Strings, like "F5" or "Shift+F5". Now the problem: On my German Windows the action doesn't fire, because the key "Shift" is called "Umsch" in German! Does it mean the SecondaryShortCuts-Property is completely useless at design time, because nobody can create applications which work internationally with that?

I could set the key at runtime by translating the VK_SHIFT into the correct name. I tried it via GetKeyNameText but this didn't worked because it gave the long form "Umschalt" not "Umsch". Anybody know the function to get the short version of the key name?

1 Answer 1

6

You could try this: Generate the shortcut text from a shortcut:

var
  s: TShortCut;
begin
  s := ShortCut(Ord('A'), [ssShift]);
  Action1.SecondaryShortCuts.Add(ShortCutToText(s));

By the way, these values are determined by the following constants. Have you translated those? And if so, do you need to?:

SmkcShift = 'Shift+';
SmkcCtrl = 'Ctrl+';
SmkcAlt = 'Alt+';
5
  • 1
    PS: I'm aware that Shift+A might not be the best shortcut if you also need to be able to type text. ;-)
    – GolezTrol
    Commented Oct 30, 2012 at 12:11
  • 1
    Thanks for hinting me in this direction. I see now its no windows issue but pure vcl. The constants (SmkcShift etc.) are resourcestrings and they are pretranslated if you use a German Delphi. The use of SecondaryShortCuts is very dangerous, because it depends on the language of the used delphi version and if you are translating the resourcestrings at runtime. Commented Oct 30, 2012 at 13:28
  • Indeed, but if you set the SecondaryShortcuts from code, you should be safe, because it translates the TShiftState to a string representation using the constant values you have loaded at that moment. Still, I agree it is odd that they chose to store those values as a translatable string.
    – GolezTrol
    Commented Oct 30, 2012 at 13:30
  • 3
    I'm stumped that somebody considered it a good idea to derive TShortCutList from TStringList. Or why Borland published that property in the OI without writing a simple property editor for it. :-/ Commented Oct 30, 2012 at 14:19
  • Indeed. It looks like they took a shortcut (no pun intended).
    – GolezTrol
    Commented Oct 30, 2012 at 14:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.