12.5 Variable typecasts

A variable can be considered a single factor in an expression. It can therefore be typecast as well. A variable can be typecast to any type, provided the type has the same size as the original variable.

It is a bad idea to typecast integer types to real types and vice versa. It’s better to rely on type assignment compatibility and using some of the standard type changing functions.

Note that variable typecasts can occur on either side of an assignment, i. e. the following are both valid typecasts:

  C : Char;  
  B : Byte;  

Pointer variables can be typecast to procedural types, but not to method pointers.

A typecast is an expression of the given type, which means the typecast can be followed by a qualifier:

  TWordRec = Packed Record  
    L,H : Byte;  
  P : Pointer;  
  W : Word;  
  S : String;