[Solved] SetFocus clears edit box


I haven’t seen such basic behaviour of a TEdit Change in many years…

In D2009 + Windows 7 64 and tested on XP. I made a simulation work without any trouble. I suspect you have AutoSelect set to True for the message editor. Therefore when focus switches back and forth the editor auto selects all the text and your next keystroke deletes it. Just happens so quickly you don’t notice.

If that’s not it you might have something else going on in FlashApplication.

Simulation using a timer:

...
edmessage.AutoSelect := False;
...

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  richedit1.SetFocus;
  richedit1.Lines.Add('Text message, interrupting typing');
  richedit1.SelStart := richedit1.GetTextLen;
  richedit1.SelLength := 0;
  richedit1.ScrollBy(0, richedit1.Lines.Count);
  richedit1.Refresh;
  edmessage.SelLength := 0;
  edmessage.SelStart := edmessage.GetTextLen;
  edmessage.SetFocus;
end;

1

solved SetFocus clears edit box