As

Belongs to : Keyword

Description

The As keyword is used for casting objects or interfaces of one type to another.

Casting allows an object to be referenced by a parent class type. For example, all objects may be referred to as a TObject class type:

button1 := Button1 As TObject;

If the object has already been cast to a parent class type, then casting to a valid child class type is allowed. The sample code shows this for the TForm class object when it is passed as a TObject type to the OnCreate method of the form.

Notes
Use the Is keyword to check for castability before attemting a cast.

Invalid casting gives EInvalidCast when you try to use the cast value.




Example code