4

Pretty simple one, but I can't find the answer.

I'm building an app in Delphi 5 Enterprise, and want my app to use the new bold black dot in a password field instead of an asterisk.

How can I do this?

Bruce McGee
  • 15,076
  • 6
  • 55
  • 70
Drarok
  • 3,612
  • 2
  • 31
  • 48

6 Answers6

10

See PasswordBox: A Better Way to Enter Passwords:

Getting the black dots to show up based on the visual style was insanely simple!

    private const int ES_PASSWORD = 0x0020;
    ...

    protected override CreateParams CreateParams
    {
        CreateParams cp = base.CreateParams;
        ...

        cp.Style |= ES_PASSWORD;
        ...

        return cp;
    }
Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
  • @Daniel A. White: Thank you. I don't know any Delphi but it ought to be fairly straightforward to translate. – Sinan Ünür Oct 20 '09 at 14:25
  • If I have a quick look in unit StdCtrls, I notice that TCustomEdit has a virtual CreateParams to override. (It even may already set the ES_PASSWORD flag when FPasswordChar<>#0 – Stijn Sanders Oct 20 '09 at 14:28
  • I've overridden CreateParams and passed ES_PASSWORD (32 in decimal?) and I still get "*" instead of the new password "blob". – Drarok Oct 20 '09 at 14:37
  • @Drarok Note that the code above is not setting `cp.Style` to `0x0020`. It is setting `cp.Style = cp.Style | 0x0020` where `|` is bitwise `or`. – Sinan Ünür Oct 20 '09 at 14:57
7

Thanks to all the above attempts, and all that contributed, but I had to join all the relevant parts together to get to a whole solution.

Thanks to Sinan Ünür for pointing out the ES_PASSWORD flag, which is used by default in Delphi, but only if PasswordChar is <> #0 (NUL).

This means that when you set PasswordChar to something, it sets the ES_PASSWORD flag, and then calls SendMessage(Handle, EM_SETPASSWORDCHAR, Ord(FPasswordChar), 0); (thanks to Stijn Sanders for pointing me towards the StdCtrls source).

If I create a subclass and bypass the line sending the EM_SETPASSWORDCHAR field, I still get only stars.

What I was forgetting to do was enable themes (which in my ancient version of Delphi requires a resource file compiling in). Hey presto, it works; Blobs abound!

So, in summary:

  1. Define the ES_PASSWORD constant if you don't already have it.

    const
      ES_PASSWORD = 32;
    
  2. Create a TEdit subclass and override CreateParams to include ES_PASSWORD in the window style.

    procedure TPasswordEdit.CreateParams(var Params: TCreateParams);
    begin
      inherited;
      Params.Style := Params.Style or ES_PASSWORD;
    end;
    
  3. Enable themes for your program.

And do not set the PasswordChar property. Done!

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
Drarok
  • 3,612
  • 2
  • 31
  • 48
3

I'm sure it uses the standard UI font. The CharMap code is U+25CF

I dunno if this will work, but you might be able to copy this.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • The problem is that in versions prior to Delphi 2009, the PasswordChar property is of type AnsiChar, which cannot hold that character. Delphi 2009 and later accept a Unicode character for that property, but according to Bruce's answer, you don't need to set the character manually because the control already shows the right character. – Rob Kennedy Oct 20 '09 at 18:44
2

According to KB 956609, the dot character is Unicode 0x25cf. It isn't tied to a particular font, but the linked page specifically mentioned that IE uses the Tahoma font.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
Ahmad Mageed
  • 94,561
  • 19
  • 163
  • 174
2

Up to Delphi 2007, using "*" for your password character would show as "*". Starting with Delphi 2009, this shows properly.

Bruce McGee
  • 15,076
  • 6
  • 55
  • 70
1

The bold black dot in password fields is Unicode character U+25CF ("BLACK CIRCLE"). Most common fonts feature this character.

Frerich Raabe
  • 90,689
  • 19
  • 115
  • 207