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
  • How to?
  • Operations performed via ExecuteProcess and via the indirection operators
  • Using ExecuteProcess
  • Using the indirection operators {... }
  • Example
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Overview
Several types of WLanguage variables are used to enumerate and dynamically handle the elements of a class. A developer who is familiar with Object-Oriented Programming (OOP) can create custom methods that adapt to the elements found in a class.
You have the ability to enumerate:
During this enumeration, you will have the ability to retrieve:
  • the element name.
  • the type of the element.
For example:
  • ability to retrieve the name of a method in order to call it by using ExecuteProcess.
  • ability to retrieve the name and type of a variable to find out or assign its value by using the indirection operators { }.
How to?
The different steps for enumerating and handling an object are as follows:
  1. Retrieving the definition of the object to handle via GetDefinition.
    Example:
    O is cWord    // Instanciation de la classe CWord
    Def is Definition // Déclaration d'une variable de type Définition
    
    Def = GetDefinition(O)  // Récupération de la définition de l'objet O dans la variable Def
    
    Trace(Def.Name)  // Affichage du nom de l'objet 
    Trace(Def.DefinitionFamily)
    Trace(Def.Type) // Affichage du type de l'objet
  2. Retrieving the list of methods. A "FOR EACH" loop is used to read the Procedure property of the Definition variable. This property corresponds to an array containing all the procedures found in the described object.
    Example:
    // Déclaration de la variable qui contiendra la description d'une procédure
    Proc is procedure Description  
    
    // Liste des procédures (ou méthodes) de l'objet Def
    FOR EACH Proc OF Def.Procedure
    	Trace (Proc.Name)  // Affiche le nom de la procédure trouvée
    END

    You can access other properties by using the PropertyName property on the object. For more details, see Procedure Description.
  3. Retrieving the list of properties. A FOR EACH loop is used to read the Property property. This property corresponds to an array containing all the properties found in the described object.
    Example:
    // Déclaration d'une variable qui contiendra la description d'une propriété
    Prop is Property Description  
    
    // Liste des propriétés de l'objet Def
    FOR EACH Prop OF Def.Property  
    	Trace (Prop.Name)  // Affiche le nom de la propriété trouvée
    END

    You can access other properties by using the PropertyName property on the object. For more details, see Property Description.
    You can also use PropertyExist to determine if a specific property exists in a class.
  4. Retrieving the list of variables. A FOR EACH loop is used to read the Variable property. This property corresponds to an array containing all the variables found in the described object.
    Example:
    // Déclaration de la variable qui contiendra la description d'une variable
    Prop is Variable Description  
    
    // Liste des variables de l'objet Def
    FOR EACH Var OF Def.Variable  
    	// Affiche le nom et le type de la Variable trouvée
    	Trace (Var.Nom, Var.Declaration.Type, Var.Definition.Nom)
    END

    You can access other properties by using the PropertyName property on the object. For more details, see Variable Description.
Operations performed via ExecuteProcess and via the indirection operators

Using ExecuteProcess

ExecuteProcess is used to call the code of an event associated with an object.
For example, the following code provokes the call of the click code of the Validate button:
ExecuteProcess(BoutonValider, trtClick)
To execute a class method, simply use a variable of type "Procedure Description" with ExecuteProcess.
For example:
c is BalloonTip
p is procedure Description
Def is Definition

Def = GetDefinition(c)
// Récupère la première procédure de l'objet BalloonTip
p = Def.Procedure[1]  

// Exécute la procédure représentée par p de l'objet c
ExecuteProcess(c, p)

Using the indirection operators {... }

Indirect operators { } can be used to manipulate the contents of a variable by indirect addressing: the name of the object to be addressed is contained in a variable..
The syntax is as follows:
{Variable_contenant_nom_Objet, TypeVariable}
where VariableType is a constant of the language starting with indXXX.
Example:
// Remplit le champ "SAI_VILLE" avec la valeur "Montpellier"
NomChamp is string
NomChamp = "SAI_VILLE"
{NomChamp, indControl} = "Montpellier"
To handle a member of a class method, all you have to do is pass in { }:
  • the instance of the class
  • a Variable Description variable or the name of the member.
For example:
c is cWord
var is Variable Description
Def is Definition

Def = GetDefinition(c)
// Récupère la 2ème variable de la classe: version de Word
var = Def.Variable[2] 

Trace(var.Name) // Affiche le nom de la variable
Trace("Version de Word: ",{c, var})  // Affiche la version de Word
Example
The code example below is used to enumerate all the procedures, properties and variables found in a class. In this example, the cWord class is issued from the "WD Controlling Word" example (provided with WINDEV).
o is cWord
def is Definition
def = GetDefinition(o)

Trace(def.Name)
Trace(def.DefinitionFamily)
Trace(defp.Type)

Proc is procedure Description
Prop is Property Description
Var is Variable Description

Trace("--------------- Procédures --------------------")
FOR EACH Proc OF def.Procedure
	Trace(Proc.Global, Proc.Inherited, Proc.Name, Proc.Virtual)
END

Trace("--------------- Propriétés --------------------")
FOR EACH Prop OF def.Property
	Trace(Prop.Declaration, Prop.Definition, Prop.Write, ...
		Prop.Global, Prop.Inherited, Prop.Read, Prop.Name, Prop.Virtual)
END

Trace("--------------- Variables --------------------")
FOR EACH Var OF def.Variable
	Trace(Var.Name, Var.Definition.Type, Var.Definition.Nom)
	SWITCH Var.Definition.Type
		CASE 1, 4, 8, 19
			// Affichage de la valeur de la variable par indirection
			Trace({o,Var})  
		CASE 34 // tableau
			Trace("Dimension: ", {o,Var.Name}..Count)
		CASE 36 // structure
			v is Variable Description
			Trace("Structure " + Var.Definition.Nom)
			Trace("........................................................")
			FOR EACH v OF Var.Definition.Variable
				Trace(v.Name, v.Definition.Type, v.Definition.Nom)
			END
			Trace("........................................................")
		OTHER CASE

	END
	Trace("======================================================================")
END
Minimum version required
  • Version 16
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 09/24/2024

Send a report | Local help