12.4 Value typecasts

Sometimes it is necessary to change the type of an expression, or a part of the expression, to be able to be assignment compatible. This is done through a value typecast. The syntax diagram for a value typecast is as follows:

_________________________________________________________________________________________________________
Typecasts

--value typecast type identifier (- expression -) -----------------------
___________________________________________________________________

Value typecasts cannot be used on the left side of assignments, as variable typecasts. Here are some valid typecasts:

Byte('A')  
Char(48)  
boolean(1)  
longint(@Buffer)

In general, the type size of the expression and the size of the type cast must be the same. However, for ordinal types (byte, char, word, boolean, enumerates) this is not so, they can be used interchangeably. That is, the following will work, although the sizes do not match.

Integer('A');  
Char(4875);  
boolean(100);  
Word(@Buffer);

This is compatible with Delphi or Turbo Pascal behavior.