|
|
|
|
|
- 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. Remark: To retrieve the instance of the current object in the class methods, use the object keyword or the this keyword. 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> <Object Name>: <Member Name> 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: - Simplified syntax, available if the following option is enabled: "Classes: optional prefixes ":" and "::" for accessing the members and methods" (this option is enabled by default for the 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> <Object Name>: <Class Name>:: <Member Name> 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> <Class Name>:: <Member Name> 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>]) Remark: For backward compatibility with the earlier versions, the following syntax can be used: ":<Method Name>([<Parameters>])". To use this syntax, uncheck "Classes: optional prefixes (":" and "::") for accessing the members and the methods". 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> ([<Parameters>]) 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 taking 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 the members declared as "XXX dynamic", the <= operator performs a copy of the reference, therefore we get the same object after the assignment. - <- operator: Taking reference
| | | | <- 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 for the arrays: Only the 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 instances of classes, all the members of the class are copied into the new instance except for the arrays. Therefore, if the value of an array member is modified, this value is modified in all the instances. To get independent arrays in all instances of classes, a local array must be declared as follows:
SystemClass is Class
aDefaultArray is local array of 1 int
END
The associative arrays, the stacks and the 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…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|