Here is a simple test:
program OrdTest;
{$APPTYPE CONSOLE}
uses
SysUtils;
begin
try
Writeln(Ord('Я'), ' ', Ord(Char('Я'))); // 223, 1071
Assert(Ord('Я') = Ord(Char('Я'))); // Fails
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.
While evaluating the Ord function with hardcoded character parameter the compiler treats the parameter as ANSI character. In the above example Ord(‘Я’) returns 223 (Cyrillic codepage 1251) instead of 1071 (UTF16) as one could expect. As a result the assertion fails (tested on Delphi XE):
After reading the comments I tried another test with both Cyrillic ‘Я’ (=223 on 1251 codepage) and German ‘ß’ (=223 on 1252 codepage):
program OrdTest2;
{$APPTYPE CONSOLE}
uses
SysUtils;
begin
try
Writeln(Ord('Я'), ' ', Ord(Char('Я')));
Writeln(Ord('ß'), ' ', Ord(Char('ß')));
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.
if I set the compiler’s codepage to 1251 I get
if I set the compiler’s codepage to 1252 I get
because German ‘ß’ has the same code (223) both in ANSI 1252 codepage and UTF16 encoding.