ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage syntax / WLanguage types / Advanced types
  • Assigning a Procedure variable
  • Multiple assignment of a Procedure variable
  • Runtime order of procedures
  • Passing Procedure parameters by reference or by value
  • Call to the procedures found in a Procedure variable
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
The Procedure type is used to handle through programming:
  • the procedures or methods found in the project.
  • the procedures or methods in an internal component.
  • the procedures or methods in an external component.
This type of variable is very useful, especially:
  • to optimize the time for starting the procedures. Using this type of variable allows you to replace the procedures run by ExecuteProcess.
  • to implement advanced algorithms (custom events, notifications, ...).
This help page presents:
Example
p is procedure
// Affectation de la variable Procédure avec la procédure "MaProcédure" présente dans le projet
p = MaProcédure
// Exécution de la procédure
p(5)
// Equivalent de MaProcédure(5)
Remarks

Assigning a Procedure variable

A Procedure variable can be assigned with:
  • a procedure known in the project.
    The following syntax must be used:
    <Nom de la variable de type Procédure> = <Procédure>

    For example:
    p is procedure
    p = TestExistence

    Remarks:
    • The <Procedure> parameter must correspond to a procedure found in the project.
    • The <Procedure> parameter must not be enclosed in quotes.
    • The <Procedure> parameter must not be followed by call parameters.
    • The <Procedure> parameter must not correspond to the name of an internal procedure.
  • WINDEV a procedure dynamically compiled by Compile.
    The following syntax must be used:
    <Nom de la variable de type Procédure> = Compile(<Code de la procédure>)

    ou

    <Nom de la variable de type Procédure> =
    Compile(<Nom Procédure>, <Code de la procédure>)

    For example:
    p is procedure
    p = Compile("RENVOYER n1 + n2")

    Remarks:
    • If the name of the procedure is specified, the procedure can also be executed by Execute and ExecuteProcess.
    • By default, the procedure dynamically compiled is a global procedure. To define a local procedure, you muse use the syntax defining the name of the procedure in order to specify the requested element in the name of the procedure.
  • a class method.
    The following syntax must be used:
    <Nom de la variable de type Procédure> = <Méthode>

    Remarks:
    • The <Method> parameter can correspond to a method of the current class or of a base class.
    • If <Method> is an instance method, the following notation should be used:
      <Un_Objet>.<Méthode>
Other possible syntaxes
  • You also have the ability to copy the procedures of a Procedure variable into another Procedure variable. The syntax is as follows:
    <Nom de la variable de type Procédure destination> =
    <Nom de la variable de type Procédure source>

    Note: This is a copy of a variable: any modification to one of the variables will not be reflected in the other..
  • You also have the ability to find at runtime a procedure identified by its name and to assign it to a Procedure variable. In this case, the following syntax must be used:
    <Nom de la variable de type Procédure> = <Nom de la procédure (avec guillemets)>

    Note: Using this syntax to assign a variable of type Procedure is relatively slow, as the procedure name is searched for in all project procedures..
  • Assignment by reference (<- operator)
    Assignment by reference means that the destination element points to the same data as the source element.
    Therefore, a Procedure variable can be handled by another Procedure variable. To do so, we must retrieve a reference on the Procedure variable itself. Any future modification made to one of the variables will be applied to the other one.
    The following syntax must be used:
    <Nom variable de type Procédure destination> <- <Nom variable de type Procédure source>

Multiple assignment of a Procedure variable

Several procedures or methods can be assigned to a Procedure variable via the "+=" operator. The different procedures will be called one after another.
For example:
p is procedure
p += Proc1
p += Proc2
Note: To delete a procedure from a variable of type Procedure, use the "-=" operator..
For example:
p is procedure
p += Proc1
p += Proc2

...

p -= Proc2

Runtime order of procedures

You have the ability to replace or insert a procedure before or after the other procedures in a Procedure element via Before and After.
Example:
p is procedure
p = MyProcedure
p.After = MyProcedureCalledAfter
p.Before = MyProcedureCalledBefore

// The order for calling the procedures will be:
// - MyProcedureCalledBefore
// - MyProcedure
// - MyProcedureCalledAfter
p()

Passing Procedure parameters by reference or by value

To handle a procedure as parameter of another procedure, you must use a typed parameter. The following syntax must be used:
  • to pass parameters by reference:
    PROCEDURE <NomProcédure>(MaProcédure est une Procédure)
  • to pass parameters by value:
    PROCEDURE <NomProcédure>(LOCAL MaProcédure est une Procédure)
The possible calls to the <ProcedureName> procedure are:
  • call specifying a procedure known to the project: the syntax to be used is as follows:
    NomProcédure(<Procédure du projet>)

    Remarks:
    • The <Project Procedure> parameter must correspond to a procedure found in the project.
    • The <Project Procedure> parameter must not be enclosed in quotes.
    • The <Project Procedure> parameter must not be followed by shortcuts.
  • call by specifying a class method: the syntax to use is as follows:
    NomProcédure(<Méthode>)

    Remarks:
    • The <Method> parameter can correspond to a method of the current class or of a base class.
    • If <Method> is an instance method, the following notation should be used: <An_Object>.<Method>.
  • call with reference to a variable procedure: the syntax to use is as follows:
    NomProcédure(<Nom de la variable de type Procédure>)
  • calls a procedure known by its name with a search at runtime: the syntax to use is as follows:
    NomProcédure(<Nom de la procédure (avec guillemets)>)

Call to the procedures found in a Procedure variable

The call to the procedures found in a Procedure variable is performed by the standard syntax of procedures. This syntax is directly used on the Procedure variable with brackets containing 0, 1 or several parameters:
<Nom de la variable Procédure> ([<Paramètre 1> [, ...[, <Paramètre N>]]])
Examples:
p1 is procedure
p1 = Proc1
p1()

p2 is procedure
p2 = Proc2
p2(1,2)
If the Procedure variable contains several procedures, all the procedures are run according to the order of assignments.
p3 is procedure
p3 += Proc3_1
p3 += Proc3_2
p3("paramètre")	// appelle Proc3_1 et Proc3_2
Managing the return value
  • If the Procedure variable contains a single procedure, the call returns the return value of the procedure.
  • If the Procedure variable contains several procedures, the call returns the return value of the last procedure called.
Related Examples:
The Procedure type Unit examples (WINDEV): The Procedure type
[ + ] Using the Procedure type of WLanguage.
This Procedure type is used to easily manage a list of procedures.
You have the ability to dynamically add some or delete some (with the += and -= operators)
Minimum version required
  • Version 17
This page is also available for…
Comments
Exemplo Procedure
// Procedure - Duas Maneiras de Mandar Informacao

PROCEDURE rotina_teste(d_recebe_data is Date="", ...
s_recebe_texto is string="")
Info(d_recebe_data)
Info(s_recebe_texto)

//Chama Procedure
//d_manda_data is date=EDT_Date
//s_manda_texto is string=EDT_Text1
//
//rotina_teste(d_manda_data,s_manda_texto)

rotina_teste.d_recebe_data=EDT_Date
rotina_teste.s_recebe_texto=EDT_Text1
rotina_teste()
//Em vez de Mandar os parametros, dentro de uma linha
//mandei os parametros individual

//Blog com Video e Exemplo

http://windevdesenvolvimento.blogspot.com.br/2017/02/aula-1068-windev-comandos-13-procedure.html

https://www.youtube.com/watch?v=EPDTU569Pu4



De matos
21 Feb. 2017

Last update: 09/20/2024

Send a report | Local help