ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage syntax / WLanguage procedures
  • Overview
  • How to?
  • Adding syntaxes to a procedure
  • Deleting a procedure syntax
  • Managing the overload at runtime
  • Basic mechanism: dynamic determination of syntax depending on the number and type of parameters
  • Dynamic dispatch
  • Virtual methods
  • Notes
  • Notes
  • Scope of procedures
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Overview
The procedures and the methods of classes can have several syntaxes.
For example, a procedure can have:
  • a syntax that takes a string as parameter.
  • a syntax that takes an integer as parameter.
Therefore, several syntaxes can exist for the same procedure or for the same method with different parameters and code. At runtime, the engine automatically defines the syntax to call according to the number and to the type of the parameters passed.
This technology is presented under several names and it includes different purposes. The following terms can be used:
  • Overload,
  • Prototype overload,
  • Overload,
  • Dynamic dispatch,
  • Parametric polymorphism,
  • etc.
This feature is available for:
  • The global procedures.
  • The local procedures.
  • The class methods including the Constructors.
    New in version 2025
    AndroidAndroid Widget Derived class constructors can now be multi-syntax.
In the rest of this document:
  • we will use the term overload.
  • the "Procedure" keyword will be used to identify a global procedure, a local procedure or a method.
How to?

Adding syntaxes to a procedure

To add a syntax to an existing procedure:
  1. In the project explorer, select the procedure.
  2. Open the context menu of the procedure and select "Add a syntax".
  3. A new syntax is automatically created in the code editor.
Remarks:
  • The creation of a procedure with the same name automatically proposes to add a new syntax to the existing procedure.
  • If a procedure has several syntaxes, the number of syntaxes is displayed in the project explorer (beside the name of the procedure).

Deleting a procedure syntax

To delete a syntax:
  1. Display the code of the procedure in the code editor.
  2. In the bar of the syntax, select "Delete" in the context menu.
  3. You can:
    • delete the current syntax.
    • delete all the syntaxes (in this case, the procedure is deleted).
Managing the overload at runtime

Basic mechanism: dynamic determination of syntax depending on the number and type of parameters

The runtime engine finds the syntax:
  • that has the same number of parameters.
  • that has the minimum number of conversions.
If two syntaxes are equivalent, the first one in the order of the code editor is run.
Basic example
// Première syntaxe
PROCEDURE p(s is string)
// Deuxième syntaxe
PROCEDURE p(n is int)
// Troisième syntaxe
PROCEDURE p(n is int, s is string)
// Quatrième syntaxe
PROCEDURE p(s is string, n is int)
// Appels

// Appelle la première syntaxe (meilleure syntaxe correspondant)
p("A")

// Appelle la deuxième syntaxe (meilleure syntaxe correspondant)
p(1)

// Appelle la troisième syntaxe (meilleure syntaxe correspondant)
p(1,"A")

// Appelle la quatrième syntaxe (meilleure syntaxe correspondant)
p("A",1)

// Appelle la troisième syntaxe 
// (équivalente à la quatrième, la troisième est prioritaire car décrite avant)
p(1,1)

// Appelle la troisième syntaxe 
// (équivalente à la quatrième, la troisième est prioritaire car décrite avant)
p("A","A")

Dynamic dispatch

For a procedure with several syntaxes whose parameters expect class instances, the runtime engine uses the "Dynamic dispatch" method to define the syntax that must be called.
Consider the following example:
  • a "BaseClass" class
  • two classes, "DerivedClass1" and "DerivedClass2", that inherit from "BaseClass".
// Première syntaxe
PROCEDURE p(LOCAL p is ClasseBase)
// Seconde syntaxe
PROCEDURE p(LOCAL p is ClasseDérivée1)
// Appels
pBase is ClasseBase dynamic
pBase = new ClasseBase		// Initialisation 
p(pBase)				// Première syntaxe
pBase = new ClasseDérivée1		// Initialisation
p(pBase)				// Seconde syntaxe
pBase = new ClasseDérivée2		// Initialisation
p(pBase)				// Première syntaxe

Virtual methods

To manage the virtual methods, several aspects can be taken into account:
  • 1st aspect: a derived class method syntax redefines a base class method syntax
    ClasseBase
    	PROCEDURE meth(s is string)
    	PROCEDURE meth(n is int)
    
    ClasseDérivée
    	PROCEDURE meth(n is int)
    
    // Appel
    oBase is ClasseBase
    // Appelle la première syntaxe dans la classe ClasseBase
    oBase.meth("A")
    // Appelle la deuxième syntaxe dans la classe ClasseBase
    oBase.meth(1)
    
    oDérivée is ClasseDérivée
    // Appelle la première syntaxe dans la classe ClasseBase
    oDérivée.meth("A")
    // Appelle la première syntaxe dans la classe ClasseDérivée
    oDérivée.meth(1)
  • 2nd aspect: additional syntax in the derived class method
    ClasseBase
    	PROCEDURE meth(p)
    	PROCEDURE meth(s is string)
    
    ClasseDérivée
    	PROCEDURE meth(n is int)
    
    // Appel
    oBase is ClasseBase
    // Appelle la deuxième syntaxe dans la classe ClasseBase
    oBase.meth("A")
    // Appelle la première syntaxe dans la classe ClasseBase
    oBase.meth(1)
    
    oDérivée is ClasseDérivée
    // Appelle la deuxième syntaxe dans la classe ClasseBase
    oDérivée.meth("A")
    // Appelle la première syntaxe dans la classe ClasseDérivée
    oDérivée.meth(1)
  • 3rd aspect: special case when the base class method and the derived class method each have a single syntax with different prototypes:
    ClasseBase
    	PROCEDURE meth(s is string)
    
    ClasseDérivée
    	PROCEDURE meth(n is int)

    The compiler cannot decide whether the method of the derived class is an override of the method of the base class or a new syntax.
    • To trigger an override, the attribute with the <override> extension must be added to the method of the derived class.
      PROCEDURE méthode(...) <redéfinition>
    • To trigger an overload, the attribute with the <overload> extension must be added to the method of the derived class.
      PROCEDURE méthode(...) <multisyntaxe>

Notes

  • In most cases, you must force the parameters to LOCAL to respect the WLanguage rules for passing parameters.
  • If the dynamic determination of the syntax finds a compatible syntax, this one can trigger a runtime error on the rules for passing parameters by reference.
Notes

Scope of procedures

The global procedures and the class method can be public, protected or private. For an overloaded procedure, the scope must be the same for all the syntaxes. A compilation error occurs if the scopes of the syntaxes are different.
Minimum version required
  • Version 16
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 09/20/2024

Send a report | Local help