3
votes

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;
1
Text is automatically fully selected when the control receives focus without any code or change in just dropped control. Which platform are we talking about?Victoria
@Victoria I noticed that the text is selected when I use the TAB key to navigate between fields. However, when I click the mouse in a field (in Windows 10) or when I touch the screen of mobile device (Android 4.4), the text isn't selected. The Edit1.SelectAll procedure also doesn't work.wBB
Aha, so the same as this just for FMX (the accepted way works for me on Windows platform). But I agree with a possible confusion from deviating from the common UX.Victoria
Oh my God!! These and others small differences between VCL and Firemonkey end up taking our time a lot. It works in OnClick event, but not in OnEnter like in VCL. Thank you again @VictoriawBB
@Calenaur The q/a you link to is about the Vcl TEdit, while this question is about the Fmx TEdit, so, not a duplicate.Tom Brunberg

1 Answers

0
votes

Have you tried to SelectAll in anonymous thread like that

TThread.CreateAnonymousThread(procedure ()
  begin
    TThread.Synchronize(nil, procedure ()
      begin
        Edit1.SelectAll();
      end);
  end).Start