Tuto WINDEV 25

Part 2: The WLanguage basics 75 In the following example, the Multiplication procedure expects two Integer parameters and returns the multiplication result. The WLanguage code of the procedure is: PROCEDURE Multiplication(Nb1 is int, Nb2 is int) MyResult is int MyResult = Nb1 * Nb2 RESULT MyResult The WLanguage code used to call the procedure is: 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 WLanguage code of the procedure is: PROCEDURE Test_address(P1) P1 = P1 * 2 • The WLanguage code used to call the procedure is: 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 WLanguage code of the procedure is: PROCEDURE Test_value(LOCAL P1) // Local indicates that the parameter will be passed by value P1 = P1 * 2

RkJQdWJsaXNoZXIy NDQ0OA==