@meeeeeeeeee: please use [code][/code] tags to properly format you code.
I'm not sure what you are trying to accomplish in your code.
Basically, if MaxLength <> 0, then the code should do nothing at all.
Also, why all the conversions (Utf8 <-> WinCP)?
If you want to know the "length in visual characters" (i.e. ä counts as 1 visual character), simply use Utf8Length().
[123456] and [123456] is counted as 6 on TEdit of Lazarus.
I'm not sure what you mean by that.
I see [123456] as a followed by a space, followed by 2, followed by a space etc., yet you talk about these as if they were multi-byte characters.
When I try with MaxLength = 6, I can type e.g. '日本語日本語' into the control, and after that nothing.
Utf8Length=6
Length=18 // 3 bytes per character
Length(UTF8towinCp(Text)=6
And Utf8ToWinCP(Edit6.Text)=?????? //the characters of the string in question cannot be translated to my Windows codepage, so they will become the '?' character.
Also, you access all individual bytes of Edit6.Text and perfom a Utf8ToWinCP() on them.
This is in itself totally non-sensical: the individual bytes of an UTF-8 encoded string have no meaning in itself as a "character".
And then you take the Length() of this???
Notice that Utf8ToWinCP with a single-byte character as input, will always return a 1-byte chacater:
- either Utf8ToWinCP will return the same character (if that charater is in the lower ASCII range), and therefor Length will be 1, or
- Utf8ToWinCP will return '?' as the input character is not valid UTF8, and again Length will be 1
Bart