How to select TEdit field text in Delphi 10


I have a very basic problem and I can't find the cause… I need the text inside a TEdit to be selected whole when the field receives focus. In the Delphi 7 days with VCL I was just doing TEdit(Sender).SelLength := Length(TEdit(Sender).Text) in the OnEnter event. Now with Delphi 10.2 and FireMonkey I've tried several different ways, but it doesn't work.


procedure TfPrincipal.Edit1Enter(Sender: TObject);
   TEdit(Sender).SelStart  := 0; // Ja tentei mudar este valor
   TEdit(Sender).SelLength := Length(TEdit(Sender).Text); // Ja tentei mudar este valor também

Does it work differently on Firemonkey?


Another thing setting SelLength a value greater than the number of SelStart characters to results in all SelStart characters being SelStart up to the end of the text.

TEdit(Sender).SetFocus ; 
TEdit(Sender).SelStart  : = 0; 
TEdit(Sender).SelLength := Length(TEdit(Sender).Text)+1;
Scroll to Top