929 new features in WINDEV, WEBDEV and WINDEV Mobile 2024

WLANGUAGE 094 N e w f e a t u r e W D W B WM CREATE YOUR OWN WLANGUAGE TYPES: FINER PROGRAMMING BY DEFAULT Imagine an application that handles prices: costs of devices, a com- modity or quantities in general. An example is the price of powder, defined in grams, with 4 deci- mal places. Rather than defining the corresponding variable in type numeric and specifying the number of digits after the decimal point each time, in version 2024 you can create a type PricePow- der and then define variables in the project using this type. You will eliminate the risk of using the wrong number of decimals. Code is automatically clearer and more consistent. Compilation attributes defined on the type are preserved on all variables of this type. Such types can then be used like native WLanguage types. In our example, you can create arrays of PricePowder variables. PricePowder is type : numeric ( 5 , 4 ) PROCEDURE CalculateColorPrice ( WeightToProduce is real, RALColor is int) : PricePowder Another, more advanced, example is the ability to define a callback type, which specifies the number and type of param- eters, and the return value expected by the callback (“delegate”). Thus, callbacks will always have the expected number of parame- ters, and the expected return value. Benefit of this new feature in version 2024 : Powerful programming possibilites 095 N e w f e a t u r e W D W B WM IMMUTABILITY A variable with the Immutable attribute can only be assigned once, and never be changed again. Unlike a constant, this variable can be conditionally initialized in the code. Immutability is also available for procedure parameters. 096 N e w f e a t u r e W D W B WM HANDLE NULL VALUES In version 2024, WLanguage manages “Null” values on all types. This allows you todirectly handle NULL items (columns) inadatabase. Variables become “nullable”. All WLanguage types become nullable: integers, strings, currencies, dates, times, etc. Nullable variables must be declared with the <Nullable> exten- sion attribute. Alternatively, you can add a question mark after the type, for example: Int? Conditions on null variables meet expected standards. The previ- ous mode for managing Null values is kept for compatibility. The new ?? , ??* and ? operators allow you to handle cases with null values. To avoid unwanted implicit conversions, the compiler generates an error when a nullable variable is assigned to a non-nullable variable. Here are some WLangage code examples: // Declaration of nullable variable n is int <nullable> // Short syntax n is int? // New operator to retrieve the variable or another variable if null v is int = n ?? 0 // Gets the default value of the type if n is null v is int = n ?? * // New operator used to call a procedure for a non-null // variable, otherwise the line is not executed s is string? = "Hello world!" r is string = s ?. Left ( 5 ) ?? "" Benefit of this new feature in version 2024 : More programming possibilities 097 N e w f e a t u r e W D W B WM BINDING & NULL VARIABLES Nullable variables make it easier to create a binding between a database and a class. Nullable variable handling is now standardized. Benefit of this new feature in version 2024 : Simplified bindings HANDLE NULL VALUES 23 N e w f e a t u r e s i n W I ND E V 2 0 2 4 WE B D E V 2 0 2 4 W I ND E V Mo b i l e 2 0 2 4