How to select TEdit field text in Delphi 10

  

I have a very basic problem and I can’t figure out why. I want to select the text of a TEdit when the field receives focus. In Delphi 7 with VCL you can do this in the OnEnter event:

TEdit(Sender).SelLength := Length(TEdit(Sender).Text)

Now, with Delphi 10.2 and FireMonkey, I’ve tried it in several different ways, but it doesn’t work.

Example:

procedure TfPrincipal.Edit1Enter(Sender: TObject);
begin
TEdit(Sender).SetFocus;
TEdit(Sender).SelStart := 0; // I already tried to change this value
TEdit(Sender).SelLength := Length(TEdit(Sender).Text); // I already tried to change this value too
end;

Comments are closed.