|
|
|
|
|
- Overview
- Handling the members of an object
- Overview
- Calling a member that belongs to an object other than the current object
- Calling a member of the current object
- Calling a member of an ancestor class that was redefined
- Calling a member of a general class
- Remark
- Handling the methods of an object
- Overview
- Calling a method that belongs to an object other than the current object
- Calling a method of the current object
- Calling a method of an ancestor class that was redefined
- Calling a method of a general class
- Example
- Remark
- Assigning objects
- Assignment rules
- Details and examples
- Instances of classes and arrays
To access a class, the object must be declared as being part of the class to handle, this is called object instantiation. An instance is an object that belongs to a given class. Note: To retrieve the current object instance from class methods, use the keyword object or the keyword this. This help page presents: Handling the members of an object Overview A member of an object is a data associated with the object. An object necessarily owns all the members described in the class. A member is also called property of the object. The members of an object correspond to all the members defined for the source class of the object. Reminder: a member is declared in the class. Calling a member that belongs to an object other than the current object To call a member that belongs to an object other than the current object, the following syntax must be used: <Object Name> . <Member Name> <Nom Objet>: <Nom Membre> The member is sought among the members of the object class. If the member is not found, it is sought among the members of the ancestor classes of the object class. Calling a member of the current object Two syntaxes can be used to call a member of the current object: - Simplifiedsyntax, available only if you enable the "Classes: optional member and method access prefixes ":" and "::"" option (this option is enabled by default on new projects):
- Full syntax (always available):
Calling a member of an ancestor class that was redefined To call a member that belongs to an ancestor class that was redefined, the following syntax must be used: <Object Name> . <Class Name> . <Member Name> <Nom Objet>: <Nom de la classe>:: <Nom Membre> Calling a member of a general class To call a member that belongs to a general class, the following syntax must be used: <Class Name> . <Member Name> <Nom de la classe>:: <Nom Membre> Remark The accesses to the members can be sequenced. For example:
MyObject.Member1[1]:Member2:Member3
Handling the methods of an object Overview The methods of an object are features associated with the object. An object necessarily owns all the methods described in the class. These methods can be called in different ways according to the location of the call. Calling a method that belongs to an object other than the current object To call a method that belongs to an object other than the current object, the following syntax must be used: <Object Name> . <Method Name> ([<Parameters>]) <Object Name>: <Method Name> ([<Parameters>]) The member is sought among the methods of the object class. If the method is not found, it is sought among the methods of the ancestor classes of the object class. Calling a method of the current object To call a method that belongs to the current object, the following syntax must be used: . <Method Name> ([<Parameters>]) Note: For compatibility with previous versions, it is possible to use the syntax ":<Method name>([<Parameters>])". To use this syntax, uncheck the "Classes: optional member and method access prefixes ":" and "::"" option. Calling a method of an ancestor class that was redefined To call a method of an ancestor class that was redefined, the following syntax must be used: <Object Name> . <Class Name> . <Method Name> ([<Parameters>]) <Object Name>: <Class Name>:: <Method Name> ([<Parameters>]) Calling a method of a general class To call a method of a general class, the following syntax must be used: <Class Name> . <Method Name> ([<Parameters>]) <Class Name>:: <Method Name> ([<Parameter>]) Example
Queue is CFile
FileD is CFile
str1,str2 are strings
Queue.FileSelection()
FileD.FileSelection()
IF Queue.RemainingSpace(FileD.Directory[[1]]) THEN
str1 = Queue:Directory + "\" + Queue:Name + "." + Queue:Extension
str2 = FileD:Directory + "\" + FileD:Name + "." + FileD:Extension
fCopyFile(str1, str2)
ELSE
Error("Insufficient space")
END
Remark The calls to methods can be used in sequence. For example:
NETObject.Metod1().Member2[n].Method3()
ClassObject.AllocateOperator().PerformOperation()
Assignment rules The assignment rules between objects and between dynamic objects are as follows: - Operator =: Copy or take reference
| | | | = operator | | Object | Dynamic object | Object | Copy | Copy | Dynamic object | Taking reference | Taking reference |
- Operator <=: Copy
| | | | <= operator | | Object | Dynamic object | Object | Copy | Copy | Dynamic object | Copy | Copy |
Note: For members declared as "XXX dynamic", the operator <= makes a copy of the reference, so we have the same object after the assignment. - Operator <-: Reference assignment
| | | | <- operator | | Object | Dynamic object | Object | Taking reference | Taking reference | Dynamic object | Taking reference | Taking reference |
Details and examples - Assignment between two objects:
- The = operator and the <= operator are used to copy members. In this case, all the members are copied into the O1 instance.
- Special case of arrays: Only local arrays are copied. All the non-local arrays use the same instance. This remark does not apply to the associative arrays.
- The <- operator is used to take a reference on the object passed in operand.
- Assignment between two dynamic objects:
pO1 is dynamic Class
pO2 is dynamic Class
pO1 = pO2
- The = operator and the <- operator are used to take reference. In this case, the dynamic variable pO1 uses the pO2 object.
- The <= operator is used to copy members. In this case, all the members are copied into the pO1 instance.
- To allow the copy with the <= operator, the dynamic variables p01 and p02 must be allocated and declared with the same type.
- Assignment between two objects (dynamic and non dynamic):
O1 is Class
pO1 is dynamic Class
pO1 = O1
O1 = pO1
- Depending on the order of the operands, the = operator is used to copy members or to take reference.
- To simplify these syntaxes, we recommend that you use the <= and < operators-:
- the <= operator is always used to perform a copy of members. For the members declared as "XXX dynamic", the <= operator performs a copy of the reference, therefore we get the same object after the assignment.
- the <- operator is always used to perform a take of reference.
O1 is Class
pO1 is dynamic Class
p01 <- O1
pO1 <= O1
Instances of classes and arrays When copying class instances, all the members of the class are copied to the new instance, except for the arrays. Therefore, if the value of an array member is modified, it is also modified in all the instances. To get an independent array in all class instances, it must be declared as follows:
SystemClass is Class
aDefaultArray is local array of 1 int
END
Associative arrays, stacks and queues cannot be declared locally.. When copying instances, the associative arrays, the queues and the stacks are automatically copied.
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|