View Issue Details

IDProjectCategoryView StatusLast Update
0002293JEDI VCL00 JVCL Componentspublic2005-01-19 14:25
ReporteranonymousAssigned Toremkobonte 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.00 BETA 2 
Target VersionFixed in Version3.00 
Summary0002293: JvEdit and PasswordChar
DescriptionHi,

when setting the PasswordChar property of JvEdit to '*' and ThemedPassword
to True and adding a XPManifest to a form, I get pretty bullets in this
edit control.

However when I toggle between PasswordChar := '*' and PasswordChar := #0
and vice versa then these bullets are changed into some asterisk instead of bullets again
TagsNo tags attached.

Activities

remkobonte

2004-11-05 16:32

developer   ~0005577

Why do you want to change PasswordChar?

Use ThemedPassword to toggle between password-mode and non password-mode.

anonymous

2004-11-08 02:22

viewer   ~0005587

@Remko,

Using e.g. JvEdit1.ThemedPassword := not JvEdit1.ThemedPassword;
to toggle the password visibility does nothing indeed. The input box get's cleared!

roaster

2004-11-08 02:25

reporter   ~0005588

As Peter suggested I'm adding a possible solution/code I've successfully used inside another control.

[..from NG posting..]

I'm restoring one of the fonts below when the PasswordChar property get
filled. First I determine one existing font and store the Font.Name into
FSecretFont. This procedure is called from the constructor.

procedure TTWPWEdit.SetEditBoxFont;
  const
    FavouredFonts: array[0..2] of String = ('Tahoma', 'Arial', 'MS Sans
Serif');
  var
    Cnt: Integer;
  begin
    Cnt := Low(FavouredFonts);
    while (Cnt <= High(FavouredFonts)) and
(Screen.Fonts.IndexOf(FavouredFonts[Cnt]) < 0) do
      Inc(Cnt);
    if Cnt <= High(FavouredFonts) then
        FSecretFont.Name := FavouredFonts[Cnt];
  end;

When the edit should display bullets I'm using a similar coding as of
JvEdit - I simply reset the font back.

try
    FInternalGetText := True;
          if HandleAllocated then
          begin
              SendMessage(WindowHandle, EM_SETPASSWORDCHAR, Ord(FSecretChar), 0);
            RecreateWnd; // Recreate to force a call to CreateParams
          end;
    Perform(WM_SETFONT, FSecretFont.Handle, 0);
      finally
          FInternalGetText := False;
      end
    else
[..]

CreateParams looks like this (similar to JvEdit):
procedure TTWPWEdit.CreateParams(var Params: TCreateParams);
  begin
    inherited;
    Params.Style := Params.Style or ES_PASSWORD;
  end;

rikbarker

2005-01-17 03:58

developer   ~0006171

Altering EM_SETPASSWORDCHAR will break theming.
Windows will correctly theme an edit box if the style ES_PASSWORD is set.

Explicitly setting a password character to use will always cause Windows to ignore theming and start using the character you specify, so don't specify one and let Windows handle it all.

This themes correctly - and can have the password exposed by setting HidePassword to false:

unit PassEdit;

interface
uses Classes, Controls, StdCtrls;

type
  TPassEdit = class(TCustomEdit)
  private
    FDummy: byte;
    FHidePassword: Boolean;
    procedure SetHidePassword(const Value: Boolean);
  protected
    procedure CreateParams(var Params: TCreateParams); override;
  public
    constructor Create(AOwner: TComponent); override;
  published
      //Snipped re-publishing of properties - don't publish PasswordChar
    property HidePassword: Boolean read FHidePassword write SetHidePassword;
  end;

implementation
uses Windows;

constructor TPassEdit.Create(AOwner: TComponent);
begin
  FHidePassword:=True;
  inherited;
  inherited ParentFont:=False;
  inherited Font.Name:= 'MS Shell Dlg';
end;

procedure TPassEdit.CreateParams(var Params: TCreateParams);
begin
  inherited;
  if FHidePassword then
    Params.Style:=Params.Style or ES_PASSWORD;
end;

procedure TPassEdit.SetHidePassword(const Value: Boolean);
begin
  if FHidePassword <> Value then
  begin
    FHidePassword:=Value;
    RecreateWnd;
  end;
end;

roaster

2005-01-17 09:21

reporter   ~0006180

@rikbarker,

thanks for your comment! If this works, untested so far, but I had a similar component/coding before, it's now up to the Jedi team to implement this into TJvEdit IMO.

cu,
Michael

remkobonte

2005-01-17 11:57

developer   ~0006184

@roaster:

I do not understand why JvEdit1.ThemedPassword := not JvEdit1.ThemedPassword; does not work for you.

Could you create a simple project with your code, maybe I'm overlooking a simple property setting.

You can upload the project to this report. Please also specify which Delphi version you use & what version of JvEdit.pas (you can find the version in the line that starts with

// $Id: JvEdit.pas

just above the unit heading).

2005-01-18 03:45

 

sample.zip (3,617 bytes)

roaster

2005-01-18 03:46

reporter   ~0006203

Hi Remko,

I've attached a sample project - and you were right: you just missed a simple but effective property: ProtectPassword.

Using D7, JvEdit: // $Id: JvEdit.pas,v 1.58 2004/12/18 07:40:43 marquardt Exp $

Thanks,
Michael

remkobonte

2005-01-18 14:00

developer   ~0006217

Last edited: 2005-01-18 14:00

Okay, problem was that toggling ThemedPassword recreates the edit window (RecreateWnd call). Because the window handle and all its data will be lost, TWinControl.DestroyWnd sends WM_GETTEXTLENGTH & WM_GETTEXT messages to save the edit text in the FText field, but that will fail if ProtectPassword is set to True.

Thus I have overridden DestroyWnd, to temporarely set ProtectPassword to False.

Also now when ThemedPassword is set to true, the font will be set to the Default GUI Font (probably MS Shell Dlg).

This is all fixed in Rev. 1.61

roaster

2005-01-19 00:41

reporter   ~0006225

Hi Remko,

works perfectly! And fixed perfectly as usual :-)
Do you close this ticket, 'cause it seems I cannot do this?

Michael

remkobonte

2005-01-19 14:25

developer   ~0006233

Okay :) thanks for the feedback.

Issue History

Date Modified Username Field Change
2004-11-05 06:17 anonymous New Issue
2004-11-05 16:32 remkobonte Note Added: 0005577
2004-11-05 16:32 remkobonte Status new => feedback
2004-11-08 02:22 anonymous Note Added: 0005587
2004-11-08 02:25 roaster Note Added: 0005588
2004-11-09 15:27 remkobonte Status feedback => assigned
2004-11-09 15:27 remkobonte Assigned To => remkobonte
2005-01-17 03:58 rikbarker Note Added: 0006171
2005-01-17 09:21 roaster Note Added: 0006180
2005-01-17 11:57 remkobonte Note Added: 0006184
2005-01-18 03:45 roaster File Added: sample.zip
2005-01-18 03:46 roaster Note Added: 0006203
2005-01-18 14:00 remkobonte Note Added: 0006217
2005-01-18 14:00 remkobonte Note Edited: 0006217
2005-01-19 00:41 roaster Note Added: 0006225
2005-01-19 14:25 remkobonte Status assigned => resolved
2005-01-19 14:25 remkobonte Fixed in Version => 3.00
2005-01-19 14:25 remkobonte Resolution open => fixed
2005-01-19 14:25 remkobonte Note Added: 0006233