ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

New WINDEV 2025 feature!
Help / WLanguage / WLanguage syntax / WLanguage procedures
  • Overview
  • A simple example
  • Advantage
  • Characteristics of a reactive procedure
  • Syntax
  • When is a reactive procedure triggered?
  • How to determine if a control is observed by a reactive procedure
  • Remarks and limitations
  • Reactive procedure observing controls
  • Variable types observed by reactive procedures
  • Limitations
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Overview
Reactive procedures are executed when the value of a control or variable changes.
For example, if a control is used in a reactive procedure, any action that modifies the value of that control will trigger the procedure. This action can be performed by the end user or programmatically.
The Reactive Procedure "observes" the variables and controls to detect value changes, and in this case, it is automatically executed.

A simple example

Here is a simple example: Entering an amount before and after tax.
When the user enters or changes the value of the amount without tax, or the tax rate, we expect the other controls to update automatically.
This operation could be written using a standard approach. We would need to create a procedure and place the call code of this procedure in the modification event for each control.
This can also be achieved using a reactive procedure. Simply create the procedure with the formula. Each time the value of the controls handled by the formula is modified, the reactive procedure is triggered.

Advantage

The main advantage of this method is that the framework takes care of "observing" for changes in control values..
This results in minimal resource consumption, as the framework takes care of everything in an optimized way. The control or variable automatically signals their change of value to the Reactive Procedure.
The code of the reactive procedure can therefore "observe" and update multiple controls and variables.
Characteristics of a reactive procedure

Syntax

A reactive procedure corresponds to a procedure local to a window. It is created in the same way as a standard local procedure. The REACTIVE keyword indicates that the procedure must observe for changes in the value of controls or variables used in its code.
Example:
REACTIVE PROCEDURE CalculateVAT()
You cannot pass parameters to a reactive procedure. However, it is possible to use extension parameters. For more details, see Declaring a procedure.
Note: The <delay = <duration in milliseconds>> extension attribute allows you to specify a delay before the execution of the reactive procedure. For example, this allows you to prevent the procedure from executing every time a character is entered in a control.

When is a reactive procedure triggered?

A reactive procedure is automatically triggered when the value of one of the controls in the window or one of the global variables in the window or controls is modified.
The reactive procedure "observes" for changes in the controls and variables.
Note: The observed controls and variables are underlined in the code of the procedure, so that you can easily identify them.
For example, the following reactive procedure observes the changes made to the EDT_Subtotal and EDT_VAT controls:
REACTIVE PROCEDURE CalculateTotal()
EDT_Total = EDT_Subtotal + EDT_Subtotal * (EDT_VAT + 1) / 100
If the reactive procedure is observing controls, it can be triggered:
  • programmatically, on any changes made to the properties of the controls. For example, you can set a procedure procedure to be triggered when the color of a control is changed.
    If the change is made in a WLanguage event associated with a control, the reactive procedure is triggered at the end of the execution of that event.
  • on a user action.
    Note: Various types of controls are currently supported. For more details, see the list of available controls in Remarks.
If the reactive procedure is observing global variables of a window, it can be triggered programmatically, on any change in the value of a variable. Only certain variable types are available. For more details, see the list of available variable types in Remarks.
How to determine if a control is observed by a reactive procedure
To determine if a control is observed by a reactive procedure, and to access the code of this or these procedure(s), an indication is displayed at the bottom of the control description window.
These buttons open the cross-reference window. For more details, see Cross-references in the code editor.
Remarks and limitations

Reactive procedure observing controls

A reactive procedure can observe:
  • changes made by the user. This applies to all controls that return a value:
    • Edit control: content modification.
    • List Box control: selection modification.
    • Check Box control and Radio Button control: selection modification.
    • Table and Looper control: Changes made to the contents of a cell in a Table control or to a control in a Looper will trigger all reactive procedures using the column or control.
    • Scrollbar, Spin, etc.: change of value.
  • WLanguage properties of controls. For example, you can set a reactive procedure on the Count property of a Table control to observe for any changes in the number of elements in the control.
Note: Using an AAF can change the value of a control. For example, the "Check all" option in a Check Box control checks all the boxes and can therefore trigger a reactive procedure.

Variable types observed by reactive procedures

A reactive procedure can observe variables of the following types:
  • Boolean
  • Integer
  • Real
  • Currency
  • Numeric
  • System integer
  • String or character
  • Date
  • Time
  • Duration
  • buffer
  • Enumeration
  • Combination
  • UUID 128 and UUID 256.

Limitations

  • Dynamic procedures cannot be used on the contents of HFSQL data files.
  • When an element is set as both a trigger and an object to be observed, the trigger takes priority.
Related Examples:
WD Reactive procedure Training (WINDEV): WD Reactive procedure
[ + ] This example presents reactive procedures in a user-friendly way, through a series of examples.
Reactive procedures observe a control or variable, and execute automatically whenever the value of that control or variable changes.
This approach is known as observer design pattern.
Minimum version required
  • Version 2025
Comments
Click [Add] to post a comment

Last update: 03/07/2025

Send a report | Local help