简体   繁体   English

如何在Delphi 10中选择TEdit字段文本

[英]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. 我想在字段获得焦点时选择TEdit的文本。 In Delphi 7 with VCL you can do this in the OnEnter event: 在带有VCL的Delphi 7中,您可以在OnEnter事件中执行此操作:

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. 现在,使用Delphi 10.2和FireMonkey,我已经尝试了几种不同的方式,但它不起作用。

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;

Have you tried to SelectAll in anonymous thread like that 您是否尝试过匿名线程中的SelectAll

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM