ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
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
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
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.
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):
    <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>
<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:
// 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>])
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

// 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 take reference
    = operator
    ObjectDynamic object
    ObjectCopyCopy
    Dynamic objectTaking referenceTaking reference
  • Operator <=: Copy
    <= operator
    ObjectDynamic object
    ObjectCopyCopy
    Dynamic objectCopyCopy
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
    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 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
    // 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 <-: reference taking
        // 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 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.
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: 10/04/2024

Send a report | Local help