[Lazarus] Unicode on Windows

Mattias Gaertner nc-gaertnma at netcologne.de
Mon Apr 9 20:39:54 CEST 2012


On Mon, 09 Apr 2012 19:23:08 +0200
Jürgen Hestermann <juergen.hestermann at gmx.de> wrote:

> Marcos Douglas schrieb:
>  > Lenght function do not works with UTF8 correctly.
>  > procedure TForm1.Button1Click(Sender: TObject);
>  > begin
>  >   Edit1.Text := 'ábç';
>  >   ShowMessage(IntToStr(Length(Edit1.Text)));
>  > end;
>  > The result is 5 not 3, but you did know this of course.
> 
> 
> Yes. For Unicode encoding we would need new functions to distinguish 
> between number of bytes and number of (visible) glyphs:
> 
> LengthInBytes()
> LengthInGlyphs()
> 
> because sometimes you need the first and sometimes (but seldom) you need 
> the latter. For one byte encodings both are identical but not for 
> Unicode. Just think of LENGTH as beeing the first version.

Length = size in bytes
UTF8Length = number of code points

There is no generic function LengthInGlyphs, because this depends on the
font engine and some code points do not have a glyph.

Mattias




More information about the Lazarus mailing list