Tuto WINDEV 25
Part 7: Advanced programming 407 ▶ Let’s go back to the code editor and study the code of first "Run" Button control. 1. Display the code of the "Run" Button control (right click on the control, "Code" option). This code calls the CompileDynamicCode procedure. 2. Position the mouse cursor on the procedure name and press F2. The procedure WLanguage code 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 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" event of the "Run" Button control 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 .
Made with FlippingBook
RkJQdWJsaXNoZXIy NDQ0OA==