Tuto WINDEV Mobile 25
92 Part 4: Programming concepts The code used to call the procedure is as follows: res is int res = Multiplication(10, 50) // Res is equal to 500 How to use the parameters? By default, passing parameters in WLanguage is performed by reference (or by address). The parameter in the procedure represents (references) the variable passed during the call. Therefore, when a procedure statement modifies the parameter value, the value of the variable corresponding to this parameter is modified. Example: • The procedure code is as follows: PROCEDURE Test_address(P1) P1 = P1 * 2 • The code used to call the procedure is as follows: T is int T = 12 // T is equal to 12 before the call Test_address(T) // T is equal to 24 after the call To avoid modifying the value of the variable corresponding to the parameter, the parameters must be passed by value . Passing parameters by value allows you to handle a copy of parameter value. If the procedure code modifies the variable value, the value of the variable corresponding to the parameter is not modified. To force a parameter to be passed by value to a procedure, the LOCAL keyword must be used in front of the parameter name in the procedure declaration. This keyword indicates that the following parameter will not be modified by the procedure. Example: • The procedure code is as follows: PROCEDURE Test_value(LOCAL P1) // Local indicates that the parameter will be passed by value P1 = P1 * 2 • The code used to call the procedure is as follows: T is int T = 12 // T is equal to 12 Test_value(T) // T does not change
Made with FlippingBook
RkJQdWJsaXNoZXIy NDQ0OA==