|
|
|
|
|
- Overview
- How to?
- Operations performed via ExecuteProcess and via the indirection operators
- Using ExecuteProcess
- Using the indirection operators {... }
- Example
Elements of a class: Enumerate and manipulate programmatically
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 { }.
The different steps for enumerating and handling an object are as follows: - Retrieving the definition of the object to handle via GetDefinition.
Example:
O is cWord
Def is Definition
Def = GetDefinition(O)
Trace(Def.Name)
Trace(Def.DefinitionFamily)
Trace(Def.Type)
- 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:
Proc is procedure Description
FOR EACH Proc OF Def.Procedure
Trace (Proc.Name)
END
You can access other properties by using the PropertyName property on the object. For more details, see Procedure Description. - 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:
Prop is Property Description
FOR EACH Prop OF Def.Property
Trace (Prop.Name)
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. - 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:
Prop is Variable Description
FOR EACH Var OF Def.Variable
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)
p = Def.Procedure[1]
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:
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)
var = Def.Variable[2]
Trace(var.Name)
Trace("Version de Word: ",{c, var})
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
Trace({o,Var})
CASE 34
Trace("Dimension: ", {o,Var.Name}..Count)
CASE 36
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
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|