New Methods
Scope
Languages: All
Objects: Procedures, Transactions, Work Panles, Web Panels
DBMS:All
Introduction
Given the method notation (<attribute>.<method>) is more 'developer friendly' than the function one (<function>(<attribute>) ), a set of new methods associated with attributes and variables were introduced.
Description
Conversion Methods
Any attribute or variable have now a set of built in methods for string conversions.
-
ToString(): Converts the value to a string. This methods avoids the need to remember which is the conversion to string function for each type, for example instead of using DTOC(&Date) use just &Date.ToString().
-
FromString(): Set the attribute or variable value from a string.
&CharacterVariable = InvoiceDate.ToString()
InvoiceDate.FromString(&CharacterVariable)
Null and Old Methods
The Null and Old functions can now be used as methods:
New Method |
Available Function |
IsEmpty |
Null |
SetEmpty |
NullValue |
IsNull |
IsNull |
SetNull |
NullValue |
GetOldValue |
Old |
// Use:
error('Invalid date') if InvoiceDate.IsEmpty()
...
// instead of
error('Invalid date') if null(InvoiceDate)
Considerations
At the Cliente Side if an attribute is null both methods (IsNull and IsEmpty) return true. In most situations GeneXus handles nulls for attributes correctly.
At the Server side only one (or none) method evaluates to true. If the attribute is null then only IsNull will be true and if it's empty, only IsEmpty returns true.
The following are a few code examples of the above statements:
Example 1: Server side evaluation
For each
Where attribute.IsEmpty() // server side execution
// Only Empty attributes
EndFor
In this case the condition is evaluated by the server side so only empty' values are retrieved.
Example 2: Client side evaluation
For Each
If attribute.IsEmpty() // client side execution
// Empty and Null attributes
EndIf
EndFor
This code is evaluated at the client side. Both null and empty values are retrieved.
There are some exceptions of this rule where GeneXus knows whether the attribute is Null or Empty in the client side:
For Each
If attribute.IsNull() // client side execution
// Null attributes
EndIf
EndFor
In this case only "Null" atributes will be retrieved. But if the condition is in another context, for example inside a subroutine, the condition will evaluate to True whenever the atribute is empty or null:
For Each attribute
Do 'Sub1'
EndFor
Sub 'Sub1'
If attribute.IsNull() // client side execution
// Empty and Null attributes
EndIf
EndSub
Enumerated Domains
-
Convert(<expression>): convert the <expression> in a valid enumerated value.
Att_based_on_an_enumerated_domain = Domain.Convert(15) //when 15 is a value available in the domain
Related Information
New Methods for already existing functions
RoundToEven Function and Method