AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Funciones WLanguage / Funciones estándar / Funciones de Windows / Funciones varias de WINDEV
  • Using the dynamic procedure
  • Dynamic code
  • Parameters of a query
  • Fields in HFSQL functions
  • Deploying of an application that uses Compile
  • Limitations
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
Dynamically compiles a procedure whose source code is supplied. The created and compiled procedure is a procedure global to the project.
Note: Functions ExecuteCode and EvaluateExpression can also be used to generate dynamically generated code.
// Syntax 1: Dynamic compilation of a global Procedure
// Source: field in which the procedure code is entered

sResult is string 
sResultCompile is string 
sResultCompile = Compile("Dynamic_Proc", MySourceCode)
SWITCH sResultCompile
	CASE "": sResult = ExecuteProcess("Proc_dynamic", trtProcedure)
	CASE "ERR": sResult = "Compilation impossible." + CR + ErrorInfo()
	OTHER CASE: sResult = sResultCompile
END
RETURN sResult
// Syntax 2: Dynamic compilation of a global procedure
// Using the Procedure type
// Source: field in which the procedure code is entered

Formula is procedure = Compile("Dynamic_Proc", MySourceCode)
IF ErrorOccurred = False THEN
	ExecuteProcess("Dynamic_Proc", trtProcedure)
	// Another way to execute the Procedure: Formula()
ELSE
	Info(ErrorInfo())
END
// Syntax 3: Dynamic compilation of a global procedure
// Direct use of the Procedure type
// Source: field in which the procedure code is entered

Formula is procedure = Compile(MySourceCode)
IF ErrorOccurred = False THEN
	Formula()
ELSE
	Info(ErrorInfo())
END
Sintaxis

Dynamic compilation of a global procedure Ocultar los detalles

<Result> = Compile(<Procedure name> , <Source code> [, <Parameters>])
<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 serious error has occurred: file wdxxxcpl.dll not found, <Code source> incorrect, no project in progress, 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.
<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".
Warning: If the function Compile is called several times with the same procedure name, the last procedure created 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).
  • This code may contain the call and declaration code of an internal procedure.
<Parameters>: Optional variable of type WLanguageCodeCompiling
WINDEV Name of WLanguageCodeCompiling variable used to define compilation parameters (WLanguage functions allowed, forbidden, etc.).
If this parameter is not specified, all WLanguage functions are allowed..
WINDEVWindowsLinuxCódigo de Usuario (UMC)

Dynamic compilation of a global procedure associated with a Procedure variable Ocultar los detalles

<Result> = Compile(<Procedure name> , <Source code> [, <Parameters>])
<Result>: Procedure variable
Name of the Procedure variable that points to the compiled procedure.
The procedure can be run:
If a compilation error occurs, the ErrorOccurred variable is set to True and ErrorInfo returns 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).
  • This code may contain the call and declaration code of an internal procedure.
<Parameters>: Optional variable of type WLanguageCodeCompiling
WINDEV Name of WLanguageCodeCompiling variable used to define compilation parameters (WLanguage functions allowed, forbidden, etc.).
If this parameter is not specified, all WLanguage functions are allowed..
WINDEVWindowsLinuxCódigo de Usuario (UMC)

Dynamic compilation of anonymous procedure Ocultar los detalles

<Result> = Compile(<Source code> [, <Parameters>])
<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.
If a compilation error occurs, the ErrorOccurred variable is set to True and ErrorInfo returns 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.
  • This code may contain the call and declaration code of an internal procedure.
<Parameters>: Optional variable of type WLanguageCodeCompiling
WINDEV Name of WLanguageCodeCompiling variable used to define compilation parameters (WLanguage functions allowed, forbidden, etc.).
If this parameter is not specified, all WLanguage functions are allowed..
Observaciones

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 function Compile FUNCTIONfunction, declare the procedure name to the WLanguage compiler using the EXTERN keyword and use the procedure directly.
  • If you are using the second syntax, to use your dynamic procedures, all you have to do is start the procedure:
  • 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:
MySourceCode is string = [
PROCEDURE AddXandY(aa, bb)
RETURN aa + bb
]
MyProc is procedure = Compile(MySourceCode)
Trace(MyProc(2, 3))

Dynamic code

Structures can be used in dynamic code.
Constants cannot be used in dynamic code (defined with 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 to be dynamically compiled, simply replace the name of the constant with its value:
    sCode is string
    sCode = [
    Info(CST_Name)
    ]
    
    // Replace the name of the constant by its value
    sCode = Replace(sCode, "CST_Name", CST_Name, WholeWord + IgnoreCase)
    
    // The code can be compiled now
    IF Compile("DynProc", sCode) <> "" THEN
    	Error("Dynamic procedure compilation error: ", ...
    		ErrorInfo())
    ELSE
    	// Then it can be run
    	WHEN EXCEPTION IN 
    		ExecuteProcess("DynProc", trtProcedure)
    	DO
    		Error("Dynamic procedure execution error: ", ...
    			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("MyQuery", hQueryDefault, "Doe")
instead of:
MyQuery.CustomerName = "Doe"
HExecuteQuery("MyQuery", hQueryDefault)

Fields in HFSQL functions

If the source code used for dynamic compilation executes an HFSQL function requiring the name of a field as a parameter, this name must be given in the form of a string enclosed in quotation marks. For example, the code to use for the HReadSeekFirst function is as follows:
HReadSeekFirst(Item, "ItemCode", "SearchValue")
instead of:
HReadSeekFirst(Item, ItemCode, "SearchValue")

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.
WINDEVCódigo de Usuario (UMC)

Limitations

  • If a project window (page) uses a local procedure with the name <Nom de la procédure>, calls to <Nom de la Procédure> from a WLanguage event in the window (page) will always execute the local procedure.
  • If a <Nom de la procédure> global procedure already exists, dynamic compilation of a <Nom de la procédure> procedure will generate 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.
Componente: wd300vm.dll
Versión mínima requerida
  • Versión 9
Esta página también está disponible para…
Comentarios
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 06 2021

Última modificación: 27/03/2025

Señalar un error o enviar una sugerencia | Ayuda local