Forum > LCL

TEdit.PasswordChar should be of type WideChar

<< < (4/4)

Zoran:

--- Quote from: Martin_fr on January 29, 2022, 08:42:31 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?

--- End quote ---

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


--- Quote from: engkin on January 29, 2022, 08:19:10 pm ---Yes!! You are right. In this case the correct condition is:
UTF16Length is 1 to fit in WPARAM.

--- End quote ---

No, the correct condition is UTF8Length = 1.


--- Quote from: engkin on January 29, 2022, 08:19:10 pm ---Because UTF8Length = 1 does not guarantee UTF16Length is not 2. In another way, it is limited to UCS-2.

--- End quote ---

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).

engkin:

--- Quote from: Zoran on January 29, 2022, 11:12:23 pm ---UTF8 covers whole unicode, all code points. It is not limited to ucs-2 subset.

--- End quote ---

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:

--- Quote from: engkin on January 30, 2022, 12:06:40 am ---
--- Quote from: Zoran on January 29, 2022, 11:12:23 pm ---UTF8 covers whole unicode, all code points. It is not limited to ucs-2 subset.

--- End quote ---

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.

--- End quote ---

Of course it will fit in wparam.
Wparam is defined as
--- Code: C  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---typedef UINT_PTR WPARAM;So unsigned, pointer-sized integer, that is at least 32-bit unsigned int.

engkin:
 :o I could not believe my eyes.
Thank you for correcting me.

PascalDragon:

--- Quote from: 440bx on January 29, 2022, 10:29:39 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.
--- End quote ---

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.

Navigation

[0] Message Index

[*] Previous page

Go to full version