ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / OOP (Object Oriented Programming)
  • 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
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Overview
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):
    <Member Name>
  • Full syntax (always available):
    :<Member Name>

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:
// Sequence of members 
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

// Call the method for file selection
Queue.FileSelection()
FileD.FileSelection()

// Call the method for checking the available space
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:
// Sequence of .NET accesses
NETObject.Metod1().Member2[n].Method3()

// Method that allocates and returns a class chained with a call
ClassObject.AllocateOperator().PerformOperation()
Assigning objects

Assignment rules

The assignment rules between objects and between dynamic objects are as follows:
  • = operator: Copy or taking reference
    = operator
    ObjectDynamic object
    ObjectCopyCopy
    Dynamic objectTaking referenceTaking reference
  • <= operator: Copy
    <= operator
    ObjectDynamic object
    ObjectCopyCopy
    Dynamic objectCopyCopy
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
    ObjectDynamic object
    ObjectTaking referenceTaking reference
    Dynamic objectTaking referenceTaking reference

Details and examples

  • Assignment between two objects:
    O1, O2 are 
    // The = operator is used to copy a member
    O1 = O2
    // Operator
    • 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
    // The = operator is used to take reference
    pO1 = pO2
    // Operator
    • 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
    // The = operator is used to take reference
    // The dynamic variable pO1 uses the O1 object
    pO1 = O1

    // The = operator is used to copy members
    // All the members are copied into the O1 instance
    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

        // <- operator: taking reference
        // The dynamic variable pO1 points to the O1 object
        p01 <- O1

        // <= operator: copying members
        // All the members are copied into the pO1 instance
        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.
For more details on instantiation, see Object instantiation.
Minimum version required
  • Version 14
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 09/07/2023

Send a report | Local help