3

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;
wBB
  • 821
  • 1
  • 18
  • 39
  • 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 Dec 21 '17 at 01:47
  • @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 Dec 21 '17 at 01:55
  • 1
    Aha, so [the same as this](https://stackoverflow.com/q/8616463/8041231) 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 Dec 21 '17 at 02:15
  • 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 @Victoria – wBB Dec 21 '17 at 02:38
  • Possible duplicate of [TEdit onclick select all?](https://stackoverflow.com/questions/8616463/tedit-onclick-select-all) –  Dec 21 '17 at 18:04
  • 1
    @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 Dec 21 '17 at 21:49

1 Answers1

0

Have you tried to SelectAll in anonymous thread like that

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