PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US

  • Using the dynamic procedure
  • Dynamic code
  • Parameters of a query
  • Deploying an application that is using the Compile function
  • Limitations
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
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
Note: ExecuteCode and EvaluateExpression also allow you to use a code that is dynamically generated.
New in version 17
Note: ExecuteCode and EvaluateExpression also allow you to use a code that is dynamically generated.
Note: ExecuteCode and EvaluateExpression also allow you to use a code that is dynamically generated.
Versions 17 and later
iPhone/iPad This function is now available for the iPhone/iPad applications.
New in version 17
iPhone/iPad This function is now available for the iPhone/iPad applications.
iPhone/iPad This function is now available for the iPhone/iPad applications.
Versions 22 and later
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
New in version 22
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
// Syntax 1: Dynamic compilation of a global procedure
// Source: control in which the procedure code is entered
sResult is string
sResultCompile is string
sResultCompile = Compile("Dynamic_Proc", MySourceCode)
SWITCH sResultCompile
CASE "": sResult = ExecuteProcess("Dynamic_Proc", trtProcedure)
CASE "ERR": sResult = "Unable to compile. " + CR + ErrorInfo()
OTHER CASE: sResult = sResultCompile
END
RESULT sResult
Versions 19 and later
// Syntax 2: Dynamic compilation of a global procedure
// Using the Procedure type
// Source: control in which the procedure code is entered

Formula is Procedure = Compile("Dynamic_Proc", MySourceCode)
IF ErrorOccurred = False THEN
ExecuteProcess("Dynamic_Proc", trtProcedure)
// Other possibility for runing the procedure: Formula()
ELSE
Info(ErrorInfo())
END
New in version 19
// Syntax 2: Dynamic compilation of a global procedure
// Using the Procedure type
// Source: control in which the procedure code is entered

Formula is Procedure = Compile("Dynamic_Proc", MySourceCode)
IF ErrorOccurred = False THEN
ExecuteProcess("Dynamic_Proc", trtProcedure)
// Other possibility for runing the procedure: Formula()
ELSE
Info(ErrorInfo())
END
// Syntax 2: Dynamic compilation of a global procedure
// Using the Procedure type
// Source: control in which the procedure code is entered

Formula is Procedure = Compile("Dynamic_Proc", MySourceCode)
IF ErrorOccurred = False THEN
ExecuteProcess("Dynamic_Proc", trtProcedure)
// Other possibility for runing the procedure: Formula()
ELSE
Info(ErrorInfo())
END
Versions 19 and later
// Syntax 3: Dynamic compilation of a global procedure
// Direct use of the Procedure type
// Source: control in which the procedure code is entered

Formula is Procedure = Compile(MySourceCode)
IF ErrorOccurred = False THEN
Formula()
ELSE
Info(ErrorInfo())
END
New in version 19
// Syntax 3: Dynamic compilation of a global procedure
// Direct use of the Procedure type
// Source: control in which the procedure code is entered

Formula is Procedure = Compile(MySourceCode)
IF ErrorOccurred = False THEN
Formula()
ELSE
Info(ErrorInfo())
END
// Syntax 3: Dynamic compilation of a global procedure
// Direct use of the Procedure type
// Source: control in which the procedure code is entered

Formula is Procedure = Compile(MySourceCode)
IF ErrorOccurred = False THEN
Formula()
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 by ExecuteProcess and Execute associated 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 error details.
  • 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 (with quotes)
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".
<Source Code>: Character string (with quotes)
Source code in WLanguage of the procedure to compile dynamically.
If this code contains quotes, they must be doubled (see the example).
If Compile is called several times with the same procedure name, the last created procedure is automatically overwritten.
PHP Source code in PHP of the procedure to compile dynamically. If this code contains quotes, they must be doubled (see the example).
Versions 19 and later
WINDEVWEBDEV - Server codeReports and QueriesWindowsLinuxiPhone/iPadWindows MobileUniversal Windows 10 AppAjaxUser code (UMC)

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 Procedure variable pointing to the compiled procedure.
The procedure can be run:
The ErrorOccurred variable is set to True if an error occurred 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".
<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).
If Compile is called several times with the same procedure name, the last created procedure is automatically overwritten.
New in version 19
WINDEVWEBDEV - Server codeReports and QueriesWindowsLinuxiPhone/iPadWindows MobileUniversal Windows 10 AppAjaxUser code (UMC)

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 Procedure variable pointing to the compiled procedure.
The procedure can be run:
The ErrorOccurred variable is set to True if an error occurred 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".
<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).
If Compile is called several times with the same procedure name, the last created procedure is automatically overwritten.
WINDEVWEBDEV - Server codeReports and QueriesWindowsLinuxiPhone/iPadWindows MobileUniversal Windows 10 AppAjaxUser code (UMC)

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 Procedure variable pointing to the compiled procedure.
The procedure can be run:
The ErrorOccurred variable is set to True if an error occurred 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".
<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).
If Compile is called several times with the same procedure name, the last created procedure is automatically overwritten.
Versions 19 and later
WINDEVWEBDEV - Server codeReports and QueriesWindowsLinuxiPhone/iPadWindows MobileUniversal Windows 10 AppAjaxUser code (UMC)

Dynamic compilation of anonymous procedure Hide the details

<Result> = Compile(<Source Code>)
<Result>: Procedure variable
Name of Procedure variable pointing to the compiled procedure.
The procedure can be run by a call to the Procedure variable.
The ErrorOccurred variable is set to True if an error occurred 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 (with quotes)
Source code in WLanguage of the procedure to compile dynamically.
If this code contains quotes, they must be doubled.
New in version 19
WINDEVWEBDEV - Server codeReports and QueriesWindowsLinuxiPhone/iPadWindows MobileUniversal Windows 10 AppAjaxUser code (UMC)

Dynamic compilation of anonymous procedure Hide the details

<Result> = Compile(<Source Code>)
<Result>: Procedure variable
Name of Procedure variable pointing to the compiled procedure.
The procedure can be run by a call to the Procedure variable.
The ErrorOccurred variable is set to True if an error occurred 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 (with quotes)
Source code in WLanguage of the procedure to compile dynamically.
If this code contains quotes, they must be doubled.
WINDEVWEBDEV - Server codeReports and QueriesWindowsLinuxiPhone/iPadWindows MobileUniversal Windows 10 AppAjaxUser code (UMC)

Dynamic compilation of anonymous procedure Hide the details

<Result> = Compile(<Source Code>)
<Result>: Procedure variable
Name of Procedure variable pointing to the compiled procedure.
The procedure can be run by a call to the Procedure variable.
The ErrorOccurred variable is set to True if an error occurred 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 (with quotes)
Source code in WLanguage of the procedure to compile dynamically.
If this code contains quotes, they must be doubled.
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.
    Other solution (not recommended): before running Compile, declare the procedure name to the WLanguage compiler via the EXTERN keyword and use the procedure directly.
  • Versions 19 and later
    If you are using the second syntax, to use your dynamic procedures, all you have to do is start the procedure:
    New in version 19
    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 second syntax, to use your dynamic procedures, all you have to do is 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 cannot expect parameters. Any value of variable must be directly specify in the code to compile.

Dynamic code

If the source code used for the dynamic compilation contains names of files, items, controls, windows, reports, queries, ... these names must necessarily be enclosed in quotes.
For example, you must use: HReadFirst("Customer", "Name") instead of HReadFirst(Customer, Name)
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 by 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_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("Error while compiling the dynamic procedure: ", ...
ErrorInfo())
ELSE
// Then it can be run
WHEN EXCEPTION IN
ExecuteProcess("DynProc", trtProcedure)
DO
Error("Error while running the dynamic procedure: ", ...
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)

Deploying an application that is using the Compile function

When deploying an application that is using Compile (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.
WINDEVWEBDEV - Server codeReports and QueriesiPhone/iPadWindows MobileUniversal Windows 10 AppAjaxUser code (UMC)

Limitations

  • If a project window (or page) uses a local procedure named <Procedure Name>, the calls to <Procedure Name> performed from a process belonging to the window (or to the 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 was overloaded, the call to this function in a code that is dynamically compiled will call the WLanguage function (and not the overloaded function). 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.
Components
WINDEVWEBDEV - Server codeReports and Queries wd230vm.dll
Windows Mobile wp230vm.dll
Linux wd230vm.so
Minimum required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment