[Lazarus] Ord of a UTF8 char

José Mejuto joshyfun at gmail.com
Sat Mar 27 15:16:03 CET 2010


Hello Lazarus-List,

Saturday, March 27, 2010, 6:05:35 AM, you wrote:

A> Ord('a') makes sense to the compiler, Ord('á') does not. Why?

Because 'a' is equal to UTF8 string #97 which is only one byte in
length. The "á" is a multibyte UTF8 sequence, more than one byte.

You can put your source code as an ANSI codepage like ISO8859-1 or
alike, but you will be in troubles with the LCL which expect
everything in UTF8 code.

If you need the "ANSI" version you can code:

ord(UTF8ToISO88591('á')[1]);

But that's awful and error prone.

Please forget ANSI codepage world, so forget to work with characters
over 127 as BYTEs. A character is a byte sequence of non fixed length
(except in UTF32). If you need ANSI output like in windows console
programs convert data just before being output and only to display the
output.

-- 
Best regards,
 José





More information about the Lazarus mailing list