Question:
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.
Example:
procedure TfPrincipal.Edit1Enter(Sender: TObject);
begin
TEdit(Sender).SetFocus;
TEdit(Sender).SelStart := 0; // Ja tentei mudar este valor
TEdit(Sender).SelLength := Length(TEdit(Sender).Text); // Ja tentei mudar este valor também
end;
Does it work differently on Firemonkey?
Answer:
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;