Edit Events does not apply to navigation keys Tab
as these do not trigger keyboard events. The only place which points to this fact. Delphi Help TCustomForm.KeyPreview
To test put 3 TEdit (CLX) on a form And a TMemo.
The tab order is Edit1, Edit2, Edit3
The only event you can use is the KeyUp Event
procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
Memo1.Lines.Add('Edit1KeyUp');
end;
procedure TForm1.Edit2KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
Memo1.Lines.Add('Edit2KeyUp');
end;
procedure TForm1.Edit3KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
Memo1.Lines.Add('Edit3KeyUp');
if Key = VK_TAB then begin
Edit2.SetFocus;
end;
end;
- put the cursor in Edit2 input field
press shift tab
- The cursor moves to the field edit1
Memo1 shows
Edit1KeyUp
Edit1KeyUp
press tab
- The cursor moves to the field edit2
Memo1 shows
Edit2KeyUp
press tab
- The cursor tries to move to the field edit3
- with the command
Edit2.SetFocus;
we send the cursor back to edit2
Memo1 shows
Edit3KeyUp
So with the TAB key the user never can leave edit2
for example : In the Edit3KeyUp event you can add a #9 to to Edit2.Text.
if Key = VK_TAB then begin
Edit2.SetFocus;
Edit2.Text := Edit2.Text+#9+'<- a Tab here';
end;