ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
  • 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 banner 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 banner 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.
  • In the lines of code present before the prototype of the Java function, only comments and imports are taken into account. Any other code will be ignored and may trigger a Error( including 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):
    // Récupération de l'activité en cours
    getActiviteEnCours()

    // Récupération du "Context" en cours
    getContexteApplication()
  • 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_Bouton1")

Generating the application

  • Android The Java classes used in the Java code must be specified in the Android application generation wizard:
    • "Integrating libraries" step for the classes included in ".jar" or ".aar" libraries.
    • "Integrating Maven dependencies" step for the 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 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 in the "Others" folder of the "Project explorer" pane ("Add elements" in 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


During 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:
PROCÉDURE GLOBAL MaProcédure(n is int, b is boolean, s is string)
...
 
RETURN s
To call the MyProcedure procedure from the Java code:
appelProcedureWL_String("MaProcedure",5,false,"test")

Important notes

  • If the procedure to be executed is a local procedure, it is recommended to specify its full name and by including 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 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 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