|
- Overview
- How to create a procedure in Java code?
- Typing the code of a global procedure in Java
- Important notes
- How to run a WLanguage procedure?
- Running a WLanguage procedure from the Java code
- Important notes
You have the ability to type Java code: - in the Java applications generated with WINDEV.
- in the Android applications generated with WINDEV Mobile.
This allows you to create global procedures in Java. Versions 17 and laterThese Java procedures can directly call the WLangage procedures of your project. New in version 17These Java procedures can directly call the WLangage procedures of your project. These Java procedures can directly call the WLangage procedures of your project. How to create a procedure in Java code? Typing the code of a global procedure in Java To type the code of a global procedure in Java: - Create a new global procedure (via "New global procedure" from the popup menu of sets of procedures in the "Project explorer" pane). Specify the name of this procedure.
- In the code editor, click the "WL" letters displayed in front of the caption of global procedure. The bar becomes purple and the "Java" characters appear in front of the procedure name. The existing code is changed into comments.
Remark: To go back to WLanguage code, all you have to do is click "Java" in the procedure bar. Important notes - Passing parameters to a Java procedure is automatically done by value.
- The parameters of procedures written in Java must necessarily be typed with a primitive type (integer, real, string, ...).
Caution: The float type is not supported, it can be replaced by the double type. - The return values of methods must necessarily correspond to a primitive type (integer, real, string, ...).
Caution: The float type is not supported, it can be replaced by the double type. - Caution: you must add the imports corresponding to the Java classes used in the native Java code entered (via the "Import" keyword). For better legibility, we advise you to add these imports before declaring the method.
The Java classes used in the native Java code must be specified in the wizard for generating the Android application: - "Integrating libraries" step for the classes included in ".jar" or ".aar" libraries.
- "Integrating Maven dependencies" step for the Maven dependencies.
Remark: The test of these classes cannot be run in GO mode. The application must be generated and started. The Java classes used in the native Java code must be specified in the wizard for generating the Java application ("Other archive files" step). Remark: The test of these classes cannot be run in GO mode. The application must be generated and started.
Versions 17 and laterHow to run a WLanguage procedure? Running a WLanguage procedure from the Java code To run a WLanguage procedure from the Java code, you must call one of the following methods according to the type of value returned by the procedure: | | Method name | Return Java type |
---|
callWLProcedure | void (no return value) | callWLProcedure_String | String | callWLProcedure_int | int | callWLProcedure_double | double | callWLProcedure_long | long | callWLProcedure_boolean | boolean |
During the call to the selected method: - the first parameter to pass to the method corresponds to the name of the WLanguage procedure to run.
- the other parameters correspond to the parameters expected by the WLanguage procedure (if necessary). You have the ability to use parameters of any simple Java type (string, int, double, long, boolean, ...). If the specified parameter does not correspond to a simple Java type, it will be automatically converted into "string" by a call to its "toString()" method.
Example: Code of WLanguage procedure:
GLOBAL PROCEDURE MyProcedure(n is int, b is boolean, s is string) ...
RESULT s
To call the MyProcedure procedure from the Java code:
callWLProcedure_String("MyProcedure",5,false,"test")
Important notes - If the procedure to run is a local procedure, we advise you to give its full name by specifying the name of the element to which the procedure belongs. Example : "WIN_Window1.MyProcedure".
- The name of procedure to run must only contain non-accented alphanumeric characters.
- If the procedure to run returns a value, this value will be automatically converted into the primitive Java type corresponding to the method used when calling the procedure. A fatal error will occur if the conversion cannot be performed.
- The procedure parameters are passed by copy.
New in version 17How to run a WLanguage procedure? Running a WLanguage procedure from the Java code To run a WLanguage procedure from the Java code, you must call one of the following methods according to the type of value returned by the procedure: | | Method name | Return Java type |
---|
callWLProcedure | void (no return value) | callWLProcedure_String | String | callWLProcedure_int | int | callWLProcedure_double | double | callWLProcedure_long | long | callWLProcedure_boolean | boolean |
During the call to the selected method: - the first parameter to pass to the method corresponds to the name of the WLanguage procedure to run.
- the other parameters correspond to the parameters expected by the WLanguage procedure (if necessary). You have the ability to use parameters of any simple Java type (string, int, double, long, boolean, ...). If the specified parameter does not correspond to a simple Java type, it will be automatically converted into "string" by a call to its "toString()" method.
Example: Code of WLanguage procedure:
GLOBAL PROCEDURE MyProcedure(n is int, b is boolean, s is string) ...
RESULT s
To call the MyProcedure procedure from the Java code:
callWLProcedure_String("MyProcedure",5,false,"test")
Important notes - If the procedure to run is a local procedure, we advise you to give its full name by specifying the name of the element to which the procedure belongs. Example : "WIN_Window1.MyProcedure".
- The name of procedure to run must only contain non-accented alphanumeric characters.
- If the procedure to run returns a value, this value will be automatically converted into the primitive Java type corresponding to the method used when calling the procedure. A fatal error will occur if the conversion cannot be performed.
- The procedure parameters are passed by copy.
How to run a WLanguage procedure? Running a WLanguage procedure from the Java code To run a WLanguage procedure from the Java code, you must call one of the following methods according to the type of value returned by the procedure: | | Method name | Return Java type |
---|
callWLProcedure | void (no return value) | callWLProcedure_String | String | callWLProcedure_int | int | callWLProcedure_double | double | callWLProcedure_long | long | callWLProcedure_boolean | boolean |
During the call to the selected method: - the first parameter to pass to the method corresponds to the name of the WLanguage procedure to run.
- the other parameters correspond to the parameters expected by the WLanguage procedure (if necessary). You have the ability to use parameters of any simple Java type (string, int, double, long, boolean, ...). If the specified parameter does not correspond to a simple Java type, it will be automatically converted into "string" by a call to its "toString()" method.
Example: Code of WLanguage procedure:
GLOBAL PROCEDURE MyProcedure(n is int, b is boolean, s is string) ...
RESULT s
To call the MyProcedure procedure from the Java code:
callWLProcedure_String("MyProcedure",5,false,"test")
Important notes - If the procedure to run is a local procedure, we advise you to give its full name by specifying the name of the element to which the procedure belongs. Example : "WIN_Window1.MyProcedure".
- The name of procedure to run must only contain non-accented alphanumeric characters.
- If the procedure to run returns a value, this value will be automatically converted into the primitive Java type corresponding to the method used when calling the procedure. A fatal error will occur if the conversion cannot be performed.
- The procedure parameters are passed by copy.
Related Examples:
|
Cross-platform examples (WINDEV Mobile): WM Expense Account
[ + ] This example allows you to manage your fees. Let's see the main features of this application: - The input of invoices - Management of foreign currencies - Inclusion of photo document for the invoices - Ability to email the expense account - Ability to track the expense accounts - ...
|
This page is also available for…
|
|
|
| |
| Click [Add] to post a comment |
|
| |
|
| |
| |
| |
| |
| |
| |
| | |
| |