FireMonkey: How to focus the next control on vkReturn?

Whiler picture Whiler · Oct 19, 2012 · Viewed 10.3k times · Source

Classic VCL question... but how to do the same within FireMonkey?

I have several standard TControl who can focus...

For instance, in some TEdit, I want to move to the next focusable control if I press the return key

I have try different approach but without success (replacing the key, keychar with 9 when it's 13, ..., forwarding the key events to the form, ...)

Of course, as it is FMX, I'd like a solution which works on all platforms...

If it can avoid to:

  • browse the Children property of the parents,
  • have different pieces of code to address the different platforms
  • hard-code the tab sequence
  • ..., it will be great ;o)

Answer

Uwe Raabe picture Uwe Raabe · Oct 19, 2012

You can place the following code into the OnKeyDown event of the form:

  if Key = vkReturn then begin
    Key := vkTab;
    KeyDown(Key, KeyChar, Shift);   
  end;

If you want that behaviour only for some of the controls, you must call this code in the OnKeyDown events of those controls.

Be aware that the KeyDown must call the TForm.KeyDown to make it work.

(Tested with XE2)