Author Topic: [SOLVED] TEDit PasswordChar not working (restricted)  (Read 3687 times)

Hansaplast

  • Hero Member
  • *****
  • Posts: 789
  • Tweaking4All.com
    • Tweaking4All
[SOLVED] TEDit PasswordChar not working (restricted)
« on: August 16, 2026, 03:50:49 pm »
Not sure when this changed, but I know it used to work in Cocoa: setting PasswordChar for a TEdit to mask password input.

Easy to reproduce:
Create a form and place a TEdit on it and set the passwordchar property to '*' (for example).
Entry will not be masked.

Screenshot: both have passwordchar set in the object inspector.

Note: This used to work and just found out by accident, after recompiling an older application where this no longer works.
It even marked as restricted for Cocoa/macOS in the object inspector, and I could not find a reference to this in bug tracker.
This happens with the latest trunk version (Lazarus 4.99 (rev main_4_99-5298-gc0b40b9d2a) FPC 3.3.1 x86_64-darwin-cocoa).

I would assume this would be a rather critical feature to have?

Did I miss something? (Rich2014?)
Does anyone know I can get this to work again or have a work around?
« Last Edit: August 24, 2026, 04:19:41 pm by Hansaplast »

Hansaplast

  • Hero Member
  • *****
  • Posts: 789
  • Tweaking4All.com
    • Tweaking4All
Re: TEDit PasswordChar not working (restricted)
« Reply #1 on: August 16, 2026, 03:54:52 pm »
p.s. setting "Echomode" to emPassword doesn't seem to work either.

jamie

  • Hero Member
  • *****
  • Posts: 7938
Re: TEDit PasswordChar not working (restricted)
« Reply #2 on: August 16, 2026, 04:47:55 pm »
If you are in a pinch, you can simulate it using the OnKeyDown event and set the KEY value to whatever value you want if the value coming in isn't less than the VK_SPACE, which would indicate a control char.

the VK_TABLE should be in LCLType unit or somewhere for you to reference.

Jamie
The only true wisdom is knowing you know nothing

Hansaplast

  • Hero Member
  • *****
  • Posts: 789
  • Tweaking4All.com
    • Tweaking4All
Re: TEDit PasswordChar not working (restricted)
« Reply #3 on: August 16, 2026, 05:19:01 pm »
Thanks for chiming in Jamie!

So wouldn't setting the key value influence the text string?


Edit: tried it and it just types the regular character one is typing, no matter what I set KEY to. 😞
« Last Edit: August 16, 2026, 05:53:28 pm by Hansaplast »

Thaddy

  • Hero Member
  • *****
  • Posts: 19805
  • Glad to be alive.
Re: TEDit PasswordChar not working (restricted)
« Reply #4 on: August 17, 2026, 02:20:51 pm »
Try this:
Code: Pascal  [Select][+][-]
  1. procedure tform1.edit1keypress(sender: tobject; var key: char);
  2. begin
  3.   // concat the real key somewhere.
  4.   if ord(key) <> VK_RETURN then Key := '*';// for now test just return.
  5. end;
That is not complete, just to test. I can't test on my M4 today.   
« Last Edit: August 17, 2026, 02:23:59 pm by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

Hansaplast

  • Hero Member
  • *****
  • Posts: 789
  • Tweaking4All.com
    • Tweaking4All
Re: TEDit PasswordChar not working (restricted)
« Reply #5 on: August 17, 2026, 03:07:25 pm »
Still does not produce the asterisks ... 😞

rca

  • Full Member
  • ***
  • Posts: 126
Re: TEDit PasswordChar not working (restricted)
« Reply #6 on: August 19, 2026, 05:20:51 am »
I have a version where it did work, but it no longer works in the current trunk.

The procedure "SetTextFieldCell" is located within the "cocoawstextedits.pas" file.
lazarus/lcl/interfaces/cocoa/cocoawstextedits.pas

In the version that worked for me:
Code: Pascal  [Select][+][-]
  1. procedure SetTextFieldCell( const edit: TCustomEdit ; const field: NSTextField );
  2. var
  3.   cell: NSTextFieldCell;
  4. begin
  5.   if (field.respondsToSelector(ObjCSelector('cell'))) and Assigned(field.cell) then
  6.   begin
  7.     if CocoaConfigEdit.vertAlignCenter then begin
  8.       cell:= TCocoaVertCenterTextFieldCell.new;
  9.       field.setCell( cell );
  10.       cell.release;
  11.     end else begin
  12.       cell:= NSTextFieldCell(field.cell);
  13.     end;
  14.     cell.setWraps(false);
  15.     cell.setScrollable(true);
  16.   end;
  17.  
  18.   ...
  19. end;

In the current version that isn't working:
Code: Pascal  [Select][+][-]
  1. procedure SetTextFieldCell( const edit: TCustomEdit ; const field: NSTextField );
  2. var
  3.   cell: TCocoaVertAlignTextFieldCell;
  4. begin
  5.   if (field.respondsToSelector(ObjCSelector('cell'))) and Assigned(field.cell) then
  6.   begin
  7.     cell:= TCocoaVertAlignTextFieldCell.new;
  8.     cell.vertAlignment:= edit.Layout;
  9.     field.setCell( cell );
  10.     cell.release;
  11.     cell.setWraps(false);
  12.     cell.setScrollable(true);
  13.   end;
  14.  
  15.   ...
  16. end;

For testing purposes only, comment out the following lines, clean, rebuild, and it will work again:
Code: Pascal  [Select][+][-]
  1.     //field.setCell( cell );
  2.     //cell.release;


Hansaplast

  • Hero Member
  • *****
  • Posts: 789
  • Tweaking4All.com
    • Tweaking4All
Re: TEDit PasswordChar not working (restricted)
« Reply #7 on: August 19, 2026, 02:33:35 pm »
Thanks RCA for chiming in. Based on what you're saying, I'll consider this a bug then or a functionality that should be fixed as it is not uncommon to be used.

Bug report can be found here: 42532

Hansaplast

  • Hero Member
  • *****
  • Posts: 789
  • Tweaking4All.com
    • Tweaking4All
Re: TEDit PasswordChar not working (restricted)
« Reply #8 on: August 20, 2026, 06:24:03 pm »
Fix in trunk by Rich2014 in minutes after I posted the bug.
Thanks Rich2014 - its much appreciated!  :)

 

TinyPortal © 2005-2018