-1

I use Delphi 10 and Windows 10.

The following code makes caret and selection disappear in Edit1.

procedure TForm1.Edit1Enter(Sender: TObject);
begin
  Edit1.PasswordChar := '*';
end;

After the focus moves to the other control and in onClick it works well.

I can't use onClick because the focus moves by tab key and the Edit1 should start with default #0 because it holds text which is 'password' before the focus enters.

How can I solve this?

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
JO SeongGng
  • 567
  • 3
  • 18
  • 4
    I can't make sense of this. Why would one setup the `PasswordChar` every time the control receives focus ? What is the motivation behind ? – TLama Sep 11 '15 at 11:15
  • @TLama i have edited the above about your comment. thanks. – JO SeongGng Sep 11 '15 at 11:18
  • 1
    `PasswordChar` is usually set in `FormCreate` or inside the `.dfm` file. It's uncommon to change it `OnEnter`. – Wosi Sep 11 '15 at 11:26

1 Answers1

8

The edit control works as designed and as expected.

  • If you want the control to hide a password then set then TEdit.PasswordChar in the OI or on creation or ... but not every time you enter the control
  • If you want to have a hint then set the TEdit.TextHint property which will be shown if TEdit.Text is empty and the control is not focused
Sir Rufo
  • 18,395
  • 2
  • 39
  • 73
  • FWIW, `TEdit.TextHint` looks like [this image](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQjZRJDrtc8x-ok92DN7u2vFfHVeQK3lCShSRTiCNJCR0g_eSe4OA). – Rudy Velthuis Sep 11 '15 at 11:59