Operations with Objects

Object Creation Operation

Syntax

$ NewOperation = New ClassType "." ProcedureCall

Description

New is an operation that is used to create a class instances, and it has the following syntax:

After the New word a base class name, a constructor name, and a parameter list should follow. Operation result is a reference to a newly created object.

The New operator is not required for classes, which parents are Real, Integer, String, Char, Date and Bool. These standard class variables are not references to objects, but they are objects themselves. Thus, the assignment operation looks as follows:

Var

a: Integer;

Begin

a := 5;

The Is Operator

Result = Operand1 Is Operand2;

The first operand is an object, the second operand is a class, interface or data type. Executing the operator results in a logical value showing whether the first operand can be cast to the class or the interface specified in Operand2.

It returns True if the object is relevant to the specified class (the object of this class or the class is a parent) or implements the specified interface.

If the conversion to a data type is checked, it is necessary to remember that the conversion is considered possible even when the data is partially lost. Remember this when working with the data via the Variant type.

The As Operator

Result = Operand1 As Operand2;

The first operand is an object, the second one is a class or an interface. Executing the operator results in an object cast to this class or the interface pointer. If the cast has been completed unsuccessfully, an exception is generated. The cast is available if the object is relevant to this class (the object of this class or the class is the parent) or implements the specified interface. An implicitly typed array can be specified as the second operand. If array size should be specified, correct transformation requires that it should match the size of the array passed in the first operand.

See also:

Operators | Casting to Fore Classes