Recent

Author Topic: TEdit.PasswordChar should be of type WideChar  (Read 5841 times)

Zoran

  • Hero Member
  • *****
  • Posts: 1751
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: TEdit.PasswordChar should be of type WideChar
« Reply #15 on: January 29, 2022, 11:12:23 pm »
The API (i.e Windows) does not matter... It's for the LCL/WS to adapt the value so it can go to the API. Also the API is also qt, gtk, cocoa ....

The property is expected to hold a single "character". The LCL uses Utf8.

So, I say, the property should be TUtf8Char.

As for any limitation to what can be set to the property:
- Some checks (such as the byte sequence to be valid utf8) can be done in the property setter.
- Subset checks may depend... If some OS accept a bigger set of chars.... Then that may be a runtime check, with some fallback, or some other solution.

Of course, the smallest common subset can be chosen, but what if the next WS to be added has a smaller subset?

Yes. And all this is actually what I said in the first place, isn't it?

Yes!! You are right. In this case the correct condition is:
UTF16Length is 1 to fit in WPARAM.

No, the correct condition is UTF8Length = 1.

Because UTF8Length = 1 does not guarantee UTF16Length is not 2. In another way, it is limited to UCS-2.

You are wrong. UTF8 covers whole unicode, all code points. It is not limited to ucs-2 subset.

LCL works with utf8 and, when needed, translates to what underlying widget api expects (in win widgetset it is utf16, in qt and gtk it is utf8, in any case we are by no means limited to ucs2).
« Last Edit: January 29, 2022, 11:15:16 pm by Zoran »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: TEdit.PasswordChar should be of type WideChar
« Reply #16 on: January 30, 2022, 12:06:40 am »
UTF8 covers whole unicode, all code points. It is not limited to ucs-2 subset.

Yes, I know, and here is why this can cause a problem on Windows. If you choose a code point outside the BMP you end up with UTF8Length = 1, but UTF16Length, in this case, is 2 and it will not fit in WPARAM.

Zoran

  • Hero Member
  • *****
  • Posts: 1751
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: TEdit.PasswordChar should be of type WideChar
« Reply #17 on: January 30, 2022, 01:22:55 am »
UTF8 covers whole unicode, all code points. It is not limited to ucs-2 subset.

Yes, I know, and here is why this can cause a problem on Windows. If you choose a code point outside the BMP you end up with UTF8Length = 1, but UTF16Length, in this case, is 2 and it will not fit in WPARAM.

Of course it will fit in wparam.
Wparam is defined as
Code: C  [Select][+][-]
  1. typedef UINT_PTR WPARAM;
So unsigned, pointer-sized integer, that is at least 32-bit unsigned int.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: TEdit.PasswordChar should be of type WideChar
« Reply #18 on: January 30, 2022, 01:49:53 am »
 :o I could not believe my eyes.
Thank you for correcting me.

PascalDragon

  • Hero Member
  • *****
  • Posts: 4765
  • Compiler Developer
Re: TEdit.PasswordChar should be of type WideChar
« Reply #19 on: January 30, 2022, 11:38:24 am »
One of the things I like best about Freepascal is that when I declare a variable to be of type "char" it's actually of type "char" ...Wow!!  Amazing, they still make compilers that parse by the rules.

The type of Char depends on the mode. In mode DelphiUnicode or if modeswitch UnicodeStrings is active the type Char is an alias to WideChar, while otherwise it's an alias to AnsiChar (just like String is an alias to UnicodeString in the former case and AnsiString in the later case, assuming that $H+ is set in both cases). This is due to compatibility with Delphi 2009 and newer.

 

TinyPortal © 2005-2018