Instance

This keyword declares an instance of a class or a representation. The instance is Null initially. You must allocate it with NewInstance before reading or writing its properties.

Syntax

Syntax is similar to other declarations, except that it requires a mandatory Using CLASS_NAME clause, where CLASS_NAMEis either:

Examples

Simple declarations:
 # Instance of a customer classLocal Instance MY_CUSTOMER Using C_CUSTOMER# Let us allocate itMY_CUSTOMER = NewInstance C_CUSTOMER AllocGroup Null# Now we can call standard methodsFmet MY_CUSTOMER.AREAD("CUST012345")# Instance of a customer representationLocal Instance MY_CUSTOMER_UI Using R_CUSTOMER
A more complex example with generic instances and cast operator:
 # Declare generic instance (will be specialized later by a cast)Local Instance OBJECT_INSTANCE Using OBJECT# Allocate an ORDERLINE instance# As OBJECT_INSTANCE is a generic instance, you cannot invoke methods on itOBJECT_INSTANCE = NewInstance C_ORDERLINE AllocGroup Null# Declare an array of 15 ORDERLINE instancesLocal Instance SORDER_LINES(1..15) Using C_ORDERLINE# Assign the previously allocated instance pointer to the first array entry. Cast is necessary here.SORDER_LINES(1) = cast(OBJECT_INSTANCE,"C_ORDERLINE")# Get the type of the first array entryTYPE=SORDER_LINES(1).Objecttype# TYPE is "C_ORDERLINE"# As SORDER_LINES(2) was not assigned, the following test will be false and Objecttype will not be calledIf SORDER_LINES(2)<>nullTYPE=SORDER_LINES(2).ObjecttypeEndif

Comments

You must provide a class or representation name when declaring an instance variable.
The special OBJECT class name allows you to declare a variable which may be assigned to an instance of any class later.
You will not be able to access properties or invoke methods on an OBJECT variable, besides built-in properties like objectType, unless you cast it first to a known class with the Cast function.

The objecttype method returns the name of the instantiation class or representation as C_CLASSNAME or R_REPNAME.

Implicit data type conversion

There are no implicit type conversions by default for an Instance. However, implicit type or property conversion may be explicitly specified in the script.


...
this.PROPERTY = MY_INSTANCE.OTHER_PROPERTY
...

In this case, the CONTROL and PROPAGATE actions will be called for this.PROPERTY.

See also

Structure, FreeInstance, FreeGroup, NewInstance, SetInstance, allocgrp, cast, null, Tinyint, Shortint, Date, Integer, Float, Double, Decimal, Char, Clbfile, Blbfile, Uuident, Datetime