Products Downloads


French version


 

 

 

Description

Once a class instance is declared in a program through the REF_CLASS instruction, a special syntax needs to be used to gain access to its attributes, for both reading and writing.

This syntax is based on the principle of Getters and Setters of object languages.

 

Getting the value of a class attribute

To retrieve the value of an attribute of a REF_CLASS type variable, the following syntax must be used:

MyVariableResult = MyInstance.getNameAttribute()

or

MyVariableResult = MyInstance.getNameAttributeArray()(index[,index2])

 

Example:

Adelia class CAR whose 4GL source is:

*attributes

{

ALPHA(15)    Make;

ALPHA(250)  Model;

NUM_BIN_2  NumHp;

DATE           DatePurch;

ALPHA(50)   Options(30)

}

 

Then in the Visual Adelia Batch program:

* Declaring a REF_CLASS variable:

REF_CLASS(CAR) iCar

NUM_BIN_2 MyBin2

DATE MyDate

ALPHA(50)   TabOptions(30)

ALPHA(50)  option;

 

* Getting the value of the attribute 'NumHp' of the iCar class:

MyBin2 = iCar.getNumHp()

 

* Getting the value of the attribute 'NumHp' of the iCar class:

MyDate = iCar.getDatePurch()

 

* Getting the value of the attribute 'Options' of the iCar class:

tabOptions = iCar.getOptions()

 

* Get the value of the first element of the attribute 'Options' from the iCar class:

Option = iCar.getOptions()(1)

 

Note:

It is assumed here that the iCar variable is already instantiated (e.g. it is one of the parameters of the input to the program or procedure), or that it has been instantiated in the program via the 4GL instruction NEW:

iCar = new CAR()

 

It is possible to test whether the iCar variable is instantiated with the reserved word *NULL:

If iCar = *NULL

 

↑ Top of page

Changing the value of a class attribute

To fix the value of an attribute of a REF_CLASS type variable, the following syntax must be used:

XXX.setYYY(ZZZ)

XXX being a variable of the REF_CLASS type

YYY being an attribute of this class

ZZZ being the value to be fixed to this attribute

 

When the attribute is a simple standard Adelia type (ALPHA, NUM_BIN_2, ..) or an overall array:

MyInstance.setNameAttribute(NewValue)

NewValue may be an alphanumeric or numeric constant, or a variable, with an Adelia type compatible with that of the attribute concerned.

 

Example:

REF_CLASS(PERSON)      iFather

ALPHA(33)                          MyAlpha33

 

iFather.setFirstname('John')

iFather.setName(MyAlpha33)

 

When it is desired to update an element of an array attribute

MyInstance.setNameAttribute(NewValue, Index1[, Index2])

 

NewValue may be an alphanumeric or numeric constant, or a variable, with an Adelia type compatible with that of the attribute concerned.

 

Index1 and Index2 may be a numeric constant or numeric variable.

 

Example:

REF_CLASS(PERSON)      iFather

REF_CLASS(CAR)             iCar

NUM_BIN_4                        MyBin4

NUM_BIN_2                        Index1

NUM_BIN_2                        Index2

 

Index = 5

iFather.setArray1DFirstnamesChildren('nicholas', Index1)

iFather.setArray1DFirstnamesChildren('virginia', 4)

 

iCar.setOptions('peugeot', 4)

iFather.setArrayBin4_2D (MyBin4, 6, 11)

iFather.setTArrayBin4_2D (444, Index1, Index2)

 

When the attribute is a class

REF_CLASS(PERSON)        iFather

REF_CLASS(FAMILY)          iFamily

Father = new PERSON()

iFamily.setFather(iFather)

↑ Top of page

  • Aucune étiquette