Vote UpVote

Be careful with Ord function in Unicode Delphi versions

The Programming Works – 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):
Favorite? Off-Topic? Serg @ 2012-11-03 11:53


Visits: 957
Votes: 2
Favorites: 0
Off-Topic: 0

Visits by Source

User Actions

Users who voted for this posting

Alister Christie
Contact us to advertise on DelphiFeeds.com

Community Links

Torry Firebird News


Please login or register to use this functionality.
(click on this box to dismiss)