ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Standard functions / Windows functions / Miscellaneous WINDEV functions
  • Project elements: fields, windows, etc.
  • Local variables
  • Compiling the code
  • Dynamic code
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
Runs the WLanguage code found in a character string.
Example
sTexte is string = "Texte"
// Affiche le texte dans une fenêtre
ExécuteCode("Info(sTexte)")
// Déclaration des variables.
sCodeAExécuter is string
xRésultatOpération is numeric

// Code WLangage à exécuter.
// Ce code renvoie le résultat d'une opération %1.
sCodeAExécuter = [
MonCalcul est un numérique
MonCalcul = %1
RENVOYER MonCalcul
]

// Code WLangage à exécuter.
// Remplacement de %1 par l'opération affichée
// dans le champ de saisie SAI_EXPRESSION.
sCodeAExécuter = StringBuild(sCodeAExécuter, SAI_EXPRESSION)

// Exécution du code et récupération du résultat.
xRésultatOpération = ExecuteCode(sCodeAExécuter)

// Affiche le résultat de l'opération dans une boîte de message de type Info()
Info("Le résultat de votre opération est : " + xRésultatOpération)
Syntax
<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.
Remark: This code may contain the call and declaration code of an internal procedure.
<Parameters>: Optional variable of type WLangageCodeCompiling
New in version 2024
WINDEVWEBDEV - Server code Name of Variable type WLangageCodeCompiling used to define compilation parameters (WLanguage functions allowed, forbidden, etc.)..
If this parameter is not specified, all WLanguage functions are allowed..
Remarks

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:
    schaine is string
    schaine = [
    Ouvrefille(fen_table)
    fen_table.afftable
    ]
    ExécuteCode(schaine)
  • Correct code:
    schaine is string
    schaine = [
    Ouvrefille("fen_table")
    x est une procédure
    x = "fen_table.afftable"
    x()
    ]
    ExécuteCode(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_Nom = 1
END
becomes for example
CST_Nom 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
// Dans la chaîne qui contient le code que l'on va compiler dynamiquement
// au lieu de laisser le nom de la constante comme ici:
sCode=[
Info(CST_Nom)
]
// On 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", trtProcedure)
DO
Error("Erreur d'exécution de la procédure dynamique : ", ExceptionInfo())
END
END
Component: wd290vm.dll
Minimum version required
  • Version 17
This page is also available for…
Comments
EXEMPLO EXECUTECODE
https://youtu.be/WsbELU020a8

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

// EXEMPLO

// EXECUTA COMANDOS

ExecuteCode(EDT_COMANDOS)
De matos
29 May 2018

Last update: 02/02/2024

Send a report | Local help