PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Assigning a Procedure variable
  • Multiple assignment of a Procedure variable
  • Runtime order of procedures
  • Passing parameters by reference or by value
  • Call to the procedures found in a Procedure variable
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
The Procedure type is used to handle by programming:
  • the procedures or methods found in the project.
  • the procedures or methods found in an internal component.
  • the procedures or methods found 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, ...).
Versions 21 and later
Universal Windows 10 App This type of variable is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This type of variable is now available in Universal Windows 10 App mode.
Universal Windows 10 App This type of variable is now available in Universal Windows 10 App mode.
Versions 22 and later
WINDEVJava This function is now available for the Java applications.
New in version 22
WINDEVJava This function is now available for the Java applications.
WINDEVJava This function is now available for the Java applications.
This help page presents:
Example
p is PROCEDURE
// Assign the Procedure variable with the "MyProcedure" procedure found in the project
p = MyProcedure
// Run the procedure
p(5)
// Equivalent to MyProcedure(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:
    <Name of Procedure variable> = <Procedure>

    For example:
    p is PROCEDURE
    p = CheckExistence

    Notes:
    • 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.
  • Versions 19 and later
    WINDEV a procedure dynamically compiled by Compile.
    The following syntax must be used:
    <Name of Procedure Variable> = Compile(<Procedure Code>)

    or

    <Name of Procedure Variable> =
    Compile(<Procedure Name>, <Procedure Code>)

    For example:
    p is PROCEDURE
    p = Compile("RESULT n1 + n2")

    Notes:
    • If the name of the procedure is specified, the procedure can also be run 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.
    New in version 19
    WINDEV a procedure dynamically compiled by Compile.
    The following syntax must be used:
    <Name of Procedure Variable> = Compile(<Procedure Code>)

    or

    <Name of Procedure Variable> =
    Compile(<Procedure Name>, <Procedure Code>)

    For example:
    p is PROCEDURE
    p = Compile("RESULT n1 + n2")

    Notes:
    • If the name of the procedure is specified, the procedure can also be run 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.
    WINDEV a procedure dynamically compiled by Compile.
    The following syntax must be used:
    <Name of Procedure Variable> = Compile(<Procedure Code>)

    or

    <Name of Procedure Variable> =
    Compile(<Procedure Name>, <Procedure Code>)

    For example:
    p is PROCEDURE
    p = Compile("RESULT n1 + n2")

    Notes:
    • If the name of the procedure is specified, the procedure can also be run 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:
    <Name of Procedure Variable> = <Method>

    Notes:
    • The <Method> parameter must correspond to a method of current class or to a method of base class.
    • If <Method> is a method of instance, the code must be run in a method of instance of the class containing the method or in a derived class.
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:
    <Name of Destination Procedure Variable> =
    <Name of Source Procedure Variable>

    Note: It is a copy of variable: any modification made to one of the variables will not be applied to the other one.
  • 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:
    <Name of Procedure Variable> = <Procedure Name (with quotes)>

    Note: Using this syntax to assign a Procedure variable takes quite a long time because the name of the procedure is sought in all the procedures of the project.
  • Assignment by reference (<- operator)
    The assignment by taking reference forces the destination element to reference the same data area 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:
    <Name of Destination Procedure Variable> <- <Name of Source Procedure Variable>

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
Versions 18 and later
Note: To delete a procedure from a Procedure variable, you have the ability to use the "-=" operator.
For example:
p is PROCEDURE
p += Proc1
p += Proc2

...

p -= Proc2
New in version 18
Note: To delete a procedure from a Procedure variable, you have the ability to use the "-=" operator.
For example:
p is PROCEDURE
p += Proc1
p += Proc2

...

p -= Proc2
Note: To delete a procedure from a Procedure variable, you have the ability to use the "-=" operator.
For example:
p is PROCEDURE
p += Proc1
p += Proc2

...

p -= Proc2
Versions 19 and later

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()
New in version 19

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()

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 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 <ProcedureName>(MyProcedure is Procedure)
  • to pass parameters by value:
    PROCEDURE <ProcedureName>(LOCAL MyProcedure is Procedure)
The possible calls to the <ProcedureName> procedure are:
  • call while specifying a procedure known by the project: the following syntax must be used:
    ProcedureName(<Project Procedure>)

    Notes:
    • 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 while specifying a class method: the following syntax must be used:
    ProcedureName(<Method>)

    Note: The <Method> parameter must correspond to a method of current class or to a method of base class.
  • call with reference to a procedure variable: the following syntax must be used:
    ProcedureName(<Name of Procedure variable>)
  • call with search at runtime for a procedure identified by its name: the following syntax must be used:
    ProcedureName(<Procedure name (with quotes)>)

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:
<Name of Procedure Variable> ([<Parameter 1> [, ...[, <Parameter 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("parameter") // calls Proc3_1 and 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.
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