0

I have a TFrame on which some TEdits are placed. These edits are boxes for serial key input, as I'm trying to setup a user experience where input focus jumps from one edit box to the next, when a certain amount of characters been entered in each. That is, user do not need to press tab or click on the next edit in order to advance.

I found an example in the C++ Builder HowTo book (great book) on how to "simulate" enter press to behave like a tab press in edits and was trying to employ the same technique. However, something in my app don't work as in that example.

In the frames KeyPress event, I have the code

void __fastcall TAboutFrame::Edit1KeyPress(TObject *Sender, 
System::WideChar &Key)
{
 TEdit* theEdit = dynamic_cast<TEdit*>(Sender);
 if(!theEdit)
 {
     return;
 }

 if(theEdit->Text.Length() >= 6)
 {
     //jump to next edit
     Perform(WM_NEXTDLGCTL, 0, 0);
...

But the 'jump' to next control does not occur.

The main Form, the frames parent, do have key preview == true and I can set a breakpoint to see that the Perform call is indeed executed.

The tab orders on the edits are 1,2,3,4,5.

I wonder if this has todo with TFrames messaging or?

Totte Karlsson
  • 1,261
  • 1
  • 20
  • 55
  • 4
    Two things: 1) You can use the `OnChange` event (rather than the `OnKeyPress`), which makes this somewhat easier, and 2) you don't need to use `Perform` and send a message; simply use `TWinControl.SelectNext`, something like `theEdit->SelectNext(theEdit, True, True)` (I say something like because I'm more up on Delphi than C++Builder) and let the VCL do all of the work for you. It correctly handles tab order. – Ken White Dec 12 '14 at 18:14
  • That worked perfect! In builder, the edits member function SelectNext is private so cannot be called, but there is a global function, SelectNext, that does the work. Thanks! – Totte Karlsson Dec 12 '14 at 18:44

1 Answers1

0

If the controls you are using descend from TWinControl (Which they should if you are using stock VCL controls), You can also use TWinControl->SetFocus() to explicitly set the focus to the desired control.