PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN

This content has been translated automatically. Click here to view the French version.
  • Using the dynamic procedure
  • Dynamic code
  • Parameters of a query
  • Deploying of an application that uses Compile
  • Limitations
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Dynamically compiles a procedure whose source code is supplied. The created and compiled procedure is a procedure global to the project.
Versions 17 and later
Remark: ExecuteCode and EvaluateExpression also allow you to use a code that is dynamically generated.
New in version 17
Remark: ExecuteCode and EvaluateExpression also allow you to use a code that is dynamically generated.
Remark: ExecuteCode and EvaluateExpression also allow you to use a code that is dynamically generated.
// Syntaxe 1: Compilation dynamique d'une procédure globale
// Source: champ dans lequel est saisi le code de procédure
 
sRésultat is string
sRésultatCompile is string
sRésultatCompile = Compile("Proc_dynamique", MonCodeSource)
SWITCH sRésultatCompile
CASE "": sRésultat = ExecuteProcess("Proc_dynamique", trtProcédure)
CASE "ERR": sRésultat = "Compilation impossible." + CR + ErrorInfo()
OTHER CASE: sRésultat = sRésultatCompile
END
RETURN sRésultat
Versions 19 and later
// Syntaxe 2: Compilation dynamique d'une procédure globale
// Utilisation du type Procédure
// Source: champ dans lequel est saisi le code de procédure
 
Formule is procédure = Compile("Proc_dynamique", MonCodeSource)
IF ErrorOccurred = False THEN
ExecuteProcess("Proc_Dynamique", trtProcédure)
// Autre possibilité pour exécuter la procédure: Formule()
ELSE
Info(ErrorInfo())
END
New in version 19
// Syntaxe 2: Compilation dynamique d'une procédure globale
// Utilisation du type Procédure
// Source: champ dans lequel est saisi le code de procédure
 
Formule is procédure = Compile("Proc_dynamique", MonCodeSource)
IF ErrorOccurred = False THEN
ExecuteProcess("Proc_Dynamique", trtProcédure)
// Autre possibilité pour exécuter la procédure: Formule()
ELSE
Info(ErrorInfo())
END
// Syntaxe 2: Compilation dynamique d'une procédure globale
// Utilisation du type Procédure
// Source: champ dans lequel est saisi le code de procédure
 
Formule is procédure = Compile("Proc_dynamique", MonCodeSource)
IF ErrorOccurred = False THEN
ExecuteProcess("Proc_Dynamique", trtProcédure)
// Autre possibilité pour exécuter la procédure: Formule()
ELSE
Info(ErrorInfo())
END
Versions 19 and later
// Syntaxe 3: Compilation dynamique d'une procédure globale
// Utilisation directe du type Procédure
// Source: champ dans lequel est saisi le code de procédure
 
Formule is procédure = Compile(MonCodeSource)
IF ErrorOccurred = False THEN
Formule()
ELSE
Info(ErrorInfo())
END
New in version 19
// Syntaxe 3: Compilation dynamique d'une procédure globale
// Utilisation directe du type Procédure
// Source: champ dans lequel est saisi le code de procédure
 
Formule is procédure = Compile(MonCodeSource)
IF ErrorOccurred = False THEN
Formule()
ELSE
Info(ErrorInfo())
END
// Syntaxe 3: Compilation dynamique d'une procédure globale
// Utilisation directe du type Procédure
// Source: champ dans lequel est saisi le code de procédure
 
Formule is procédure = Compile(MonCodeSource)
IF ErrorOccurred = False THEN
Formule()
ELSE
Info(ErrorInfo())
END
Syntax

Dynamic compilation of a global procedure Hide the details

<Result> = Compile(<Procedure name> , <Source code>)
<Result>: Character string
Compilation result:
  • Empty string ("") if the compilation was successful. The procedure can be run using ExecuteProcess and Execute with the trtProcedure constant.
  • ERR if a fatal error occurred: wdxxxcpl.dll not found, incorrect <Source code>, no current project, global procedure already created, etc. ErrorInfo returns the details of the error.
  • An error message if a compilation error was detected. This message corresponds to the caption of the error.
PHP This parameter is not available. This function returns no result.
<Procedure name>: Character string
Name of dynamic global procedure to create.
To create a local procedure, all you have to do is specify the element name. For example: "WindowName.ProcedureName".
Caution: If Compile is called several times with the same procedure name, the last created procedure is automatically overwritten.
<Source code>: Character string
Source code in WLanguage of the procedure to compile dynamically.
  • If this code contains quotes, they must be doubled (see the example).
  • Versions 25 and later
    This code may contain the call and declaration code of an internal procedure.
    New in version 25
    This code may contain the call and declaration code of an internal procedure.
    This code may contain the call and declaration code of an internal procedure.
PHP Source code in PHP of the procedure to compile dynamically. If this code contains quotes, they must be doubled.
Versions 19 and later
WEBDEV - Server codeWindowsLinuxAjax

Dynamic compilation of a global procedure associated with a Procedure variable Hide the details

<Result> = Compile(<Procedure name> , <Source code>)
<Result>: Procedure variable
Name of the Procedure variable that points to the compiled procedure.
The procedure can be run:
In case of a compilation error, the Variable ErrorOccurred is True and the ErrorInfo function is used to obtain the error details.
<Procedure name>: Character string
Name of dynamic global procedure to create.
To create a local procedure, all you have to do is specify the element name. For example: "WindowName.ProcedureName".
If Compile is called several times with the same procedure name, the last created procedure is automatically overwritten.
<Source code>: Character string
Source code in WLanguage of the procedure to compile dynamically.
  • If this code contains quotes, they must be doubled (see the example).
  • Versions 25 and later
    This code may contain the call and declaration code of an internal procedure.
    New in version 25
    This code may contain the call and declaration code of an internal procedure.
    This code may contain the call and declaration code of an internal procedure.
New in version 19
WEBDEV - Server codeWindowsLinuxAjax

Dynamic compilation of a global procedure associated with a Procedure variable Hide the details

<Result> = Compile(<Procedure name> , <Source code>)
<Result>: Procedure variable
Name of the Procedure variable that points to the compiled procedure.
The procedure can be run:
In case of a compilation error, the Variable ErrorOccurred is True and the ErrorInfo function is used to obtain the error details.
<Procedure name>: Character string
Name of dynamic global procedure to create.
To create a local procedure, all you have to do is specify the element name. For example: "WindowName.ProcedureName".
If Compile is called several times with the same procedure name, the last created procedure is automatically overwritten.
<Source code>: Character string
Source code in WLanguage of the procedure to compile dynamically.
  • If this code contains quotes, they must be doubled (see the example).
  • Versions 25 and later
    This code may contain the call and declaration code of an internal procedure.
    New in version 25
    This code may contain the call and declaration code of an internal procedure.
    This code may contain the call and declaration code of an internal procedure.
WEBDEV - Server codeWindowsLinuxAjax

Dynamic compilation of a global procedure associated with a Procedure variable Hide the details

<Result> = Compile(<Procedure name> , <Source code>)
<Result>: Procedure variable
Name of the Procedure variable that points to the compiled procedure.
The procedure can be run:
In case of a compilation error, the Variable ErrorOccurred is True and the ErrorInfo function is used to obtain the error details.
<Procedure name>: Character string
Name of dynamic global procedure to create.
To create a local procedure, all you have to do is specify the element name. For example: "WindowName.ProcedureName".
If Compile is called several times with the same procedure name, the last created procedure is automatically overwritten.
<Source code>: Character string
Source code in WLanguage of the procedure to compile dynamically.
  • If this code contains quotes, they must be doubled (see the example).
  • Versions 25 and later
    This code may contain the call and declaration code of an internal procedure.
    New in version 25
    This code may contain the call and declaration code of an internal procedure.
    This code may contain the call and declaration code of an internal procedure.
Versions 19 and later
WEBDEV - Server codeWindowsLinuxAjax

Dynamic compilation of anonymous procedure Hide the details

<Result> = Compile(<Source code>)
<Result>: Procedure variable
Name of the Procedure variable that points to the compiled procedure.
The procedure can be run by a call to the Procedure variable.
In case of a compilation error, the Variable ErrorOccurred is True and the ErrorInfo function is used to obtain the error details.
The procedure is compiled as a global procedure. To compile a procedure associated with a window, you must name the procedure (syntax 2).
<Source code>: Character string
Source code in WLanguage of the procedure to compile dynamically.
  • If this code contains quotes, they must be doubled.
  • Versions 25 and later
    This code may contain the call and declaration code of an internal procedure.
    New in version 25
    This code may contain the call and declaration code of an internal procedure.
    This code may contain the call and declaration code of an internal procedure.
New in version 19
WEBDEV - Server codeWindowsLinuxAjax

Dynamic compilation of anonymous procedure Hide the details

<Result> = Compile(<Source code>)
<Result>: Procedure variable
Name of the Procedure variable that points to the compiled procedure.
The procedure can be run by a call to the Procedure variable.
In case of a compilation error, the Variable ErrorOccurred is True and the ErrorInfo function is used to obtain the error details.
The procedure is compiled as a global procedure. To compile a procedure associated with a window, you must name the procedure (syntax 2).
<Source code>: Character string
Source code in WLanguage of the procedure to compile dynamically.
  • If this code contains quotes, they must be doubled.
  • Versions 25 and later
    This code may contain the call and declaration code of an internal procedure.
    New in version 25
    This code may contain the call and declaration code of an internal procedure.
    This code may contain the call and declaration code of an internal procedure.
WEBDEV - Server codeWindowsLinuxAjax

Dynamic compilation of anonymous procedure Hide the details

<Result> = Compile(<Source code>)
<Result>: Procedure variable
Name of the Procedure variable that points to the compiled procedure.
The procedure can be run by a call to the Procedure variable.
In case of a compilation error, the Variable ErrorOccurred is True and the ErrorInfo function is used to obtain the error details.
The procedure is compiled as a global procedure. To compile a procedure associated with a window, you must name the procedure (syntax 2).
<Source code>: Character string
Source code in WLanguage of the procedure to compile dynamically.
  • If this code contains quotes, they must be doubled.
  • Versions 25 and later
    This code may contain the call and declaration code of an internal procedure.
    New in version 25
    This code may contain the call and declaration code of an internal procedure.
    This code may contain the call and declaration code of an internal procedure.
Remarks

Using the dynamic procedure

  • If you are using the first syntax, to use your dynamic procedures, all you have to do is run the procedure via ExecuteProcess or Execute.
    Another solution (not recommended): before executing the Compilefunction, declare the name of the Procedure to the WLanguage compiler with the EXTERN keyword and use the Procedure directly.
  • Versions 19 and later
    If you are using the second syntax, to use your dynamic procedures, simply start the procedure:
    New in version 19
    If you are using the second syntax, to use your dynamic procedures, simply start the procedure:
    If you are using the second syntax, to use your dynamic procedures, simply start the procedure:
  • Versions 19 and later
    If you are using the third syntax, to use your dynamic procedures, all you have to do is run the procedure via a direct call to the Procedure variable.
    New in version 19
    If you are using the third syntax, to use your dynamic procedures, all you have to do is run the procedure via a direct call to the Procedure variable.
    If you are using the third syntax, to use your dynamic procedures, all you have to do is run the procedure via a direct call to the Procedure variable. A procedure that is dynamically compiled can take parameters. Example:
MonCodeSource is string = [
PROCÉDURE AdditionneXetY(aa, bb)
RENVOYER aa + bb
]
MaProc is procédure = Compile(MonCodeSource)
Trace(MaProc(2, 3))

Dynamic code

The constants cannot be used in the dynamic code (defined by the CONSTANT keyword).
When using constants in a code, all the occurrences of the constants are replaced with their value during the compilation in the editor but the correspondence between the name of constants and their value is not "embedded" in the application. Therefore, the dynamic compilation cannot use the constants.
Let's see two alternatives:
1st solution: Use variables instead of constants.
The code:
CONSTANT
CST_Name = 1
END
becomes for example
CST_Name is int = 1
2nd solution: In the string containing the code that must be compiled dynamically, replace the name of the constant by its value:
sCode is string
sCode = [
Info(CST_Nom)
]
 
// Remplace le nom de la constante par sa valeur
sCode = Replace(sCode, "CST_Nom", CST_Nom, WholeWord + IgnoreCase)
 
// Il est ensuite possible de compiler le code
IF Compile("ProcDyn", sCode) <> "" THEN
Error("Erreur de compilation de la procédure dynamique: ", ...
ErrorInfo())
ELSE
// Puis de l'exécuter
WHEN EXCEPTION IN
ExecuteProcess("ProcDyn", trtProcédure)
DO
Error("Erreur d'exécution de la procédure dynamique: ", ...
ExceptionInfo())
END
END

Parameters of a query

If the source code used for the dynamic compilation runs a query with parameters (HExecuteQuery), the parameters expected by the query must necessarily be specified in HExecuteQuery.
For example, you must use:
HExecuteQuery("MaRequête", hQueryDefault, "Dupont")
instead of:
MaRequête.NomClient = "Dupont"
HExecuteQuery("MaRequête", hQueryDefault)

Deploying of an application that uses Compile

When deploying an application that usesCompile (when creating the executable or deploying the site), you must specify all the libraries of the WINDEV/WEBDEV/WINDEV Mobile framework used by the code that is dynamically compiled. Indeed, this code being compiled dynamically, WINDEV, WEBDEV and WINDEV Mobile do not detect the framework libraries used.
WEBDEV - Server codeAjax

Limitations

  • If a project window (or page) uses a local procedure named <Procedure name>, the calls to <Procedure name> from a process belonging to the window (or page) will always run the local procedure.
  • If a global procedure named <Procedure name> already exists, the dynamic compilation of a procedure named <Procedure> will trigger an error.
  • By default, overloading the WLanguage functions is ignored during the dynamic compilation.
    For example, if Trace has been overloaded, the WLanguage function (not the overloaded function) will be called in a code that is dynamically compiled. To force the use of the overloaded function during the dynamic compilation, the name of the function must be preceded by the "Extern" keyword.
  • The enumerations and the combinations are not available in dynamic compilation.
Related Examples:
Dynamic compilation Unit examples (WINDEV): Dynamic compilation
[ + ] Dynamic compilation of WLanguage code (stored in string format), execution of the dynamically generated procedure and process of possible runtime errors.
The dynamic compilation is very useful when mathematical calculations are proposed to the end user for example.
Component: wd270vm.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
exemplo compile e execute
https://windevdesenvolvimento.blogspot.com/2021/05/dicas-3340-windev-webdev-mobile-compile.html
https://youtu.be/fSx8ybbBZws

//initializing - pode ser colocado no global caso precisar
CONSTANT
// Nome do procedimento que é compilado dinamicamente
DYNAMIC_PROCEDURE = "DYNAMIC_PROCEDURE"
END

// BOTAO CALCULA - ACIONAR O AJAX
EDT_resultado_compilacao=Compile(dynamic_procedure,EDT_comandos)
IF EDT_resultado_compilacao="" THEN
Execute(dynamic_procedure)
EDT_resultado_compilacao="Compilado corretamente"
ELSE
EDT_resultado_compilacao="Erro"+ErrorInfo(errFullDetails)
END
amarildo
01 Jun. 2021