PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
New WINDEV 24 feature!
  • This lesson will teach you the following concepts
  • Overview
  • Example
Lesson 7.4. Dynamic compilation
This lesson will teach you the following concepts
  • Overview.
  • Drawing a line in dynamic compilation.

Estimated time: 20 mn
Previous LessonTable of contentsNext Lesson
Overview
The dynamic compilation is used to compile a code at any time in the application. A common example? Your application contains a formula that can be configured. To change the parameters, there is no need to provide the executable again: the modification of a text file is sufficient.
Example
The dynamic compilation will be presented via the unit example named "Dynamic compilation".
The "Dynamic compilation" window explains how to dynamically compile WLanguage code (stored in string format), run the procedure that was dynamically generated and process the possible runtime errors.
  • To run the test of this window:
    1. Open the unit example named "Dynamic compilation".
    2. Run the test of "WIN_DYNAMIC_COMPILATION" window.
    3. Click the different "Run" buttons to see the different cases.
    4. Stop the test.
  • Let's go back to the code editor and study the code of first "Run" button.
    1. Display the code of "Run" button (right click on the button, "Code" option). This code calls the CompileDynamicCode procedure.
    2. Position the mouse cursor on the procedure name and press F2. The procedure code is automatically displayed in the code editor.
      The code of this procedure can be divided into several sections:
      1. Initializing the variables.
      2. Compiling the code.
        sCompilationResult = Compile(DYNAMIC_PROCEDURE, EDT_COMPIL_CODE)
        This code contains several important points:
        • The function is compiled by the WLanguage function Compile. The function that is dynamically compiled becomes usable as soon as this function is called (and if no error is returned).
        • This function expects two parameters: the name of compiled procedure ("DYNAMIC_PROCEDURE") and the code to compile. In this case, the code to compile is found in the EDT_COMPIL_CODE edit control.
        • The compilation result is assigned to a sCompilationResult string.
      3. Checking the compilation result.
        // Checks the compilation result
        SWITCH sCompilationResult
        // No error
        CASE ""
        bCompilationResult = True
        STC_ERROR_CODE_COMPILE = ""

        // Fatal compilation error
        CASE "ERR"
        bCompilationResult = False
        STC_ERROR_CODE_COMPILE = ErrorInfo()
        // Incorrect code
        OTHER CASE
        bCompilationResult = False
        STC_ERROR_CODE_COMPILE = sCompilationResult
        END
    3. Press Ctrl + F2. The click code of "Run" button re-appears in the code editor. In the rest of this code, you can see that the function that is dynamically compiled is run by Execute.
Previous LessonTable of contentsNext Lesson
Minimum version required
  • Version 24
Comments
Click [Add] to post a comment