ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / Developing in Java
  • Overview
  • How to create a procedure in Java?
  • Writing a global procedure in Java
  • Important notes
  • Generating the application
  • How to execute a WLanguage procedure?
  • Executing a WLanguage procedure from the Java code
  • Important notes
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Overview
You can use Java code:
  • in Java applications generated with WINDEV.
  • in Android applications generated with WINDEV Mobile.
This allows you to create global procedures in Java.
These Java procedures can directly call the WLanguage procedures of your project.
How to create a procedure in Java?

Writing a global procedure in Java

To write a global procedure in Java:
  1. Create a new global procedure (via "New global procedure" in the context menu of sets of procedures in the "Project explorer" pane). Specify the name of this procedure.
  2. The procedure is created in the code editor.
  3. In the header of the procedure, click "WL" to change the type of code.
    Native Java before
  4. In the list that opens, select "Java".
  5. The header becomes purple and "Java" appears to the left of the procedure name. The existing code is commented out.
    Native Java after
  6. Write the Java code directly in the code editor in WINDEV and/or WINDEV Mobile.
Remark: To switch back to WLanguage code, simply click "Java" in the procedure header and select "WLanguage".

Important notes

  • In Java procedures, parameters are automatically passed by value.
  • The parameters of procedures written in Java must be of a primitive type (integer, real, string, etc.).
    Caution: The float type is not supported, it can be replaced with the double type.
  • The return values of methods must be of a primitive type (integer, real, string, etc.).
    Caution: The float type is not supported, it can be replaced with the double type.
  • Caution: you need to import the classes used in the native Java code with the "Import" keyword. It is recommended to import these elements before declaring the method.
  • Only comments and imported elements are taken in into account in the lines of code before the prototype of the Java function. Any other code will be ignored and may trigger an error (especially missing parenthesis).
  • Java is case-sensitive: make sure you always use the same lowercase and uppercase characters in the function names.
Android Android specific features:
  • If the Java code entered requires specific permissions, they must be explicitly defined when generating the application. For more details, see Generating an Android application.
  • The classes and methods of Android SDK often handle a reference on a "Context" object. In an Android project, when writing native code, you can retrieve a "Context" object by referencing the current activity or the application context via the following methods (these methods can be directly called in the code of the procedure):
    // Get the current activity
    getCurrentActivity()

    // Get the current "Context"
    getApplicationContext()
  • To retrieve the View object corresponding to the main control component, you must use the getView method while passing the control name.
    Example: The following code returns the instance of the "Button" class used by the control:
    getView("BTN_Button1")

Generating the application

  • Android The Java classes used in the native Java code must be specified in the Android application generation wizard:
    • "Integrate libraries" step for classes included in ".jar" or ".aar" libraries.
    • "Integrate Maven dependencies" step for Maven dependencies.
      Remark: These classes cannot be tested via the GO option. The application must be generated and launched.
  • Java The Java classes used in the native Java code must be specified in the Java application generation wizard ("Other archive files" step).
    Remark: These classes cannot be tested via the GO option. The application must be generated and launched.
  • Automatically take into account external classes: To automatically take external Java classes into account when generating the application:
    • Add the files to the "Other" folder of the "Project explorer" pane (via the "Add elements" option of the context menu).
      Caution: Java files must be encoded in UTF-8.
    • If the Java class belongs to a package, this package must be declared in the first line of the file. If the package is not specified, the file will be located in <Package_AppName>.wdgen with the other generated ".java" files.
How to execute a WLanguage procedure?

Executing a WLanguage procedure from the Java code

To execute a WLanguage procedure from the Java code, simply call one of the following methods depending on the type of the value returned by the procedure:
Method nameReturn Java type
callWLProcedurevoid (no return value)
callWLProcedure_StringString
callWLProcedure_intint
callWLProcedure_doubledouble
callWLProcedure_longlong
callWLProcedure_booleanboolean


In the call to the selected method:
  • the first parameter the method takes is the name of the WLanguage procedure to be executed.
  • the other parameters correspond to the parameters expected by the WLanguage procedure (if necessary). You can use parameters of any simple Java type (string, int, double, long, boolean, etc.). If the specified parameter does not correspond to a simple Java type, it will be automatically converted to "string" by calling its "toString()" method.
Example:
Code of WLanguage procedure:
GLOBAL procedure MyProcedure(n is int, b is boolean, s is string)
...
RETURN s
To call the MyProcedure procedure from the Java code:
callWLProcedure_String("MyProcedure",5,false,"test")

Important notes

  • If the procedure to be executed is a local procedure, it is recommended to specify its full name and include the name of the element to which the procedure belongs. Example: "WIN_Window1.MyProcedure".
  • The name of the procedure to be executed must contain only unaccented alphanumeric characters.
  • If the procedure to be executed returns a value, this value will be automatically converted to the primitive Java type corresponding to the method used to call the procedure. If the conversion fails, a fatal error occurs.
  • The parameters of the procedure are passed by value.
Related Examples:
WM Expense Account 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
- ...
Minimum version required
  • Version 10
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 06/26/2023

Send a report | Local help