User Tools

Site Tools

Navigation:  Language Reference > 3 - Variable Declarations > Special Data Types >====== LIKE (inherited data type) ====== Previous pageReturn to chapter overviewNext page

new declaration LIKE(like declaration) [,DIM( )] [,OVER( )] [,PRE( )] [,NAME( )] [,EXTERNAL]



LIKE Declares a variable whose data type is inherited from another variable.
new declaration The label of the new data element declaration.
like declaration The label of the data element declaration whose definition will be used. This may be any simple data type, or a reference to any simple data type (except &STRING), or the label of a GROUP or QUEUE structure.
DIM Dimension the variables into an array.
OVER Share a memory location with another variable or structure.
PRE Declare a label prefix for variables within the new declaration structure (if the like declaration is a complex data structure). This is not required, since you may use the new declaration in the Field Qualification syntax to directly reference any member of the new structure.
NAME Specify an alternate, “external” name for the field.
EXTERNAL Specify the variable is defined, and its memory is allocated, in an external library. Not valid within FILE, QUEUE, or GROUP declarations.
DLL Specify the variable is defined in a .DLL. This is required in addition to the EXTERNAL attribute.
STATIC Specify the variable's memory is permanently allocated.
THREAD Specify memory for the variable is allocated once for each execution thread. Also implicitly adds the STATIC attribute on Procedure Local data.
BINDABLE Specify all variables in the group may be used in dynamic expressions.

LIKE tells the compiler to define the new declaration using the same definition as the like declaration, including all attributes. If the original like declaration changes, so does the new declaration.

The new declaration may use the DIM and OVER attributes. If the like declaration has a DIM attribute, the new declaration is already an array. If a further DIM attribute is added to the new declaration, the array is further dimensioned.

The PRE and NAME attributes may be used, if appropriate. If the like declaration already has these attributes, the new declaration will inherit them and compiler errors can occur. To correct this, specify a PRE or NAME attribute on the new declaration to override the inherited attribute.

If the like declaration names a QUEUE, LIKE does not create a new QUEUE, because the like declaration is simply treated as a GROUP. The like declaration QUEUE is converted to a new declaration GROUP. The same is true if the like declaration is a RECORD structure. Similarly, if the like declaration is a MEMO, the new declaration becomes a STRING of the maximum size of the MEMO.

You may use LIKE to create a new instance of a CLASS. However, simply declaring the new instance by naming the CLASS as the data type performs an implicit LIKE. For either type of instance declaration, the DIM, OVER, PRE, and NAME attributes are invalid; all other attributes are valid for a CLASS instance declaration.


Amount       REAL                 !Define a field

QTDAmount    LIKE(Amount)         !Use same definition

YTDAmount    LIKE(QTDAmount)      !Use same definition again

MonthlyAmts  LIKE(Amount),DIM(12) !Use same definition for array, 12 elements

AmtPrPerson  LIKE(MonthlyAmts),DIM(10)

            !Use same definition for array of 120 elements (12,10)

Construct GROUP                   !Define a group

Field1     LIKE(Amount)           ! Construct.field1 - real

Field2     STRING(10)             ! Construct.field2 - string(10)


NewGroup  LIKE(Construct)        !Define new group, containing

                                ! NewGroup.field1 - real

                                ! NewGroup.field2 - string(10)

MyQue    QUEUE                   !Define a queue

Field1     STRING(10)

Field2     STRING(10)


MyGroup  LIKE(MyQue)             !Define new GROUP, like the QUEUE

AmountFile FILE,DRIVER('Clarion'),PRE(Amt)

Record      RECORD

Amount       REAL          !Define a field

QTDAmount    LIKE(Amount)  !Use same definition



Animal    CLASS

Feed        PROCEDURE(short amount),VIRTUAL

Die         PROCEDURE

Age         LONG

Weight      LONG


Cat       LIKE(Animal) !New instance of an Animal CLASS

Bird      Animal       !New instance of an Animal CLASS (implicit LIKE)

See Also:





Field Qualification

like_inherited_data_type_.htm.txt · Last modified: 2021/04/15 15:57 by