ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

New WINDEV 28 feature!
  • In this lesson you will learn the following concepts
  • Overview
  • Example
Lesson 7.4. Dynamic compilation
In this lesson you will learn the following concepts
  • Overview.
  • Drawing a line in dynamic compilation.
Lesson duration

Estimated time: 20 mn
Previous LessonTable of contentsNext Lesson
Overview
The dynamic compilation is used to compile code at any time in the application. For example, your application contains a formula that can be configured. To change the parameters, there is no need to provide the executable again: simply modify a text file.
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 test this window:
    1. Open the "Dynamic compilation" unit example.
    2. Test the "WIN_DYNAMIC_COMPILATION" window.
    3. Click the "Run" buttons to see the different cases.
    4. Stop the test.
  • Let's go back to the code editor to see the code of the first "Run" button.
    1. Open the code of the "Run" button (right-click the control and select "Code"). This code calls the CompileDynamicCode procedure.
    2. Move the mouse cursor to the procedure name and press F2. The WLanguage code of the procedure is automatically displayed in the code editor.
      The code of this procedure can be divided into several sections:
      1. Initializing variables.
      2. Compiling the code.
        sCompilationResult = Compile(DYNAMIC_PROCEDURE, EDT_COMPIL_CODE)
        This code contains several important points:
        • The function is compiled by the Compile WLanguage function. The dynamically compiled function can be used once the function is called (if no error is returned).
        • This function expects two parameters: the name of the compiled procedure ("DYNAMIC_PROCEDURE") and the code to compile. In this case, the code to compile is 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_COMPILED_CODE = ""
         
        // Fatal compilation error
        CASE "ERR"
        bCompilationResult = False
        STC_ERROR_COMPILED_CODE = ErrorInfo()
        // Incorrect code
        OTHER CASE
        bCompilationResult = False
        STC_ERROR_COMPILED_CODE = sCompilationResult
        END
    3. Press Ctrl + F2. The "Click" event of the "Run" button appears again 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 28
Comments
Click [Add] to post a comment