I’m having trouble with the following scenario:
- 2 Edit’s
- Type something in Edit1 and press TAB, focus goes to Edit2
- Edit1.OnExit -> show a Form with a message “Processing…” (makes a lengthy validation)
After the form closes, the focus on Edit2 seems to be “crashed”…
– the hole TEXT in Edit2 isn’t selected
– the carret isn’t flashing
Example:
- Create a new form
- Put 2 edits
-
Set this as OnExit event in Edit1:
procedure TForm1.Edit1Exit(Sender: TObject); begin with TForm.CreateNew(self) do try Width := 100; Height := 50; Position := poMainFormCenter; show; sleep(200); finally Free; end; end; -
Run the application
- Set focus in the Edit1 and press TAB
I’m using:
- Delphi 7 Enterprise
- Windows 7 x64
I’m not sure precisely what’s going on here, but it looks like the order of processing of messages is a bit messed up. Instead of killing your other form with
Free, useReleaseand the focus will behave as you desire.Another option is to use
ShowModalinstead ofShow. Normally you show a processing dialog modally because you don’t want the user making modifications to the main form whilst you are processing. If you do that then you can carry on usingFree.