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
  • Project elements: fields, windows, etc.
  • Local variables
  • Compiling the code
  • Dynamic code
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
Runs the WLanguage code found in a character string.
Ejemplo
sText is string = "Text"
// Displays the text in a window
ExecuteCode("Info(sText)")
// Declare the variables.
sCodeToRun is string
xOperationResult is numeric

// WLanguage code to run. 
// This code returns the result of an operation %1.
sCodeToRun = [
	MyCalculation is numeric
	MyCalculation = %1
	RETURN MyCalculation
	]

// WLanguage code to run. 
// Replace %1 by the operation displayed 
// in the EDT_EXPRESSION edit control.
sCodeToRun = StringBuild(sCodeToRun, EDT_EXPRESSION)

// Run the code and retrieve the result.
xOperationResult = ExecuteCode(sCodeToRun)

// Displays the result of the operation in an Info message box
Info("The result of your operation is: " + xResultOperation)
Sintaxis
<Result> = ExecuteCode(<Code> [, <Parameters>])
<Result>: Any type
  • Result of the code if it contains a RETURN statement,
  • Nothing otherwise. In this case, an error message may be displayed when the result is assigned in a variable for example.
<Code>: Character string
WLanguage code to run.
Note: This code may contain the call and declaration code of an internal procedure.
<Parameters>: Optional variable of type WLanguageCodeCompiling
WINDEVWEBDEV - Código Servidor 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

Project elements: fields, windows, etc.

Project elements are not known in the dynamic code. It is necessary to use the syntaxes with character strings.
Example:
  • Error code:
    sstring is string
    sstring = [
    OpenChild(fen_table)
    fen_table.afftable
    ]
    ExecuteCode(schaine)
  • Correct code:
    sstring is string
    sstring = [
    OpenChild("fen_table")
    x is a Procedure
    x = "fen_table.afftable"
    x()
    ]
    ExecuteCode(schaine)

Local variables

The local variables of the current process can be directly used in the code to run.
If the code is compiled without error, the code is run directly.
A fatal error is triggered if the code is not compiled.

Compiling the code

The code is recompiled each time ExecuteCode is called.
To avoid the compilation step, you have the ability to use Compile and Execute.

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:
1 - Use variables instead of constants
CONSTANT
	CST_Name = 1
END
becomes for example
CST_Name is int = 1
ou
2 - In the string containing the code that must be compiled dynamically, replace the name of the constant by its value:
sCode is string
// In the string containing the code that will be compiled dynamically
// instead of leaving the name of the constant:
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
Componente: wd300vm.dll
Versión mínima requerida
  • Versión 17
Esta página también está disponible para…
Comentarios
EXEMPLO EXECUTECODE
https://youtu.be/WsbELU020a8

http://doc.windev.com/en-US/?1000019783&name=ExecuteCode

// EXEMPLO

// EXECUTA COMANDOS

ExecuteCode(EDT_COMANDOS)
De matos
29 05 2018

Última modificación: 27/03/2025

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