Casting to Fore Classes

In some cases developing custom projects may require expanding properties or methods of the standard form by inheriting from custom classes or interfaces. The further access to custom properties or methods requires to cast the forms to a custom class or interface. If on executing a program you cannot determine for sure whether a form can be cast to a custom class or a custom interface, use the Is operator to check the form for the ability to be cast. A standard checking option using the MDI application is given below.

Example

Executing the example requires the main MDI form and several child MDI forms. The main MDI form contains a toolbar with two buttons. One of the child MDI forms contains an extension using the IUserInterface user interface. One property is described in the interface, the property implementation is represented in the form class. A possible form code is given below:

After executing the example, clicking the buttons on the toolbar of the main MDI form checks if an active child MDI form can be cast to the IUserInterface user interface. If it can be cast, the UserProp property value described in the IUserInterface interface is read or set depending on the button pressed. On reading the value is displayed to form header. A random real number is used as the value to be set.

See also:

Operations with Objects | As | Is