Help says: Chr returns a character with an ordinal value (ASCII value) byte type expression, X. *
So, how is a character represented in computer memory? Guess what, like a byte *. In fact, the functions Chr and Ord exist only where Pascal is a strongly typed language that prohibits the use of bytes *, where characters are requested. For a computer, the resulting char is still represented as a byte * - what will it be converted to then? Actually, there is no code for this function call, just as there is no code omitted for the type. Ergo: no difference.
You may prefer chr to avoid typecasting.
Note. Type casting should not be confused with explicit type conversions! In Delphi 2010, something like Char(a) is written, and an - AnsiChar, actually does something.
** For Unicode, replace the byte with an integer *
Edit:
Just an example to make it clear (assuming non-Unicode):
var a: Byte; c: char; b: Byte; begin a := 60; c := Chr(60); c := Chr(a); b := a; end;
creates a similar code
ftest.pas.46: a := 60; 0045836D C645FB3C mov byte ptr [ebp-$05],$3c ftest.pas.47: c := Chr(60); 00458371 C645FA3C mov byte ptr [ebp-$06],$3c ftest.pas.48: c := Chr(a); 00458375 8A45FB mov al,[ebp-$05] 00458378 8845FA mov [ebp-$06],al ftest.pas.49: b := a; 0045837B 8A45FB mov al,[ebp-$05] 0045837E 8845F9 mov [ebp-$07],al
Assigning a byte to byte actually matches the assignment of a char byte via CHR ().
source share