As a 4D developer, you’ve probably already created and used formulas. They can be created via two commands, Formula and Formula from string. The latter has just been enhanced in 4D v20 R3 to be used without limits from components!
Formulas and execution context
Formulas, whatever their content, are intimately linked to the database from which they are created. When called, they are always executed in the context in which they were created.
This applies to 4D commands and functions like Structure file and formulas based on method calls.
A simple example
Let’s imagine a FormatedCurrentDate method that returns a formatted string.
#DECLARE($format : Integer)->$formatedDate : Text
$formatedDate:=String(Current date; $format)
This method can be used within a formula, which can be created this way:
$formula:=Formula from string("FormatedCurrentDate(System date abbreviated)")
In this case, the formula will return the formatted date as expected.
$date:=$formula.call()
When the method and the formula are in the same environment, all is fine… but if this not shared method is in the host database, and the formula that tries to use this method is created within a component, it won’t be able to execute.
A new parameter is now available
A new parameter has been added to the Formula from the string function to give you the choice and allow you to decide in which context the formula will be executed.
#1) sk execute in the host database
If we return to the previous example, where the FormatedCurrentDate unshared method belongs to the host database, it will be possible to execute it anyway from a component by creating the formula as follows:
$formula:=Formula from string("FormatedCurrentDate(System date abbreviated)";sk execute in host database)
#2) sk execute in the current database
If the value sk execute in the current database is passed (or is simply omitted), then the formula will be executed in the database that created the formula”.
Conclusion
This new option will enable you to easily create your own interface components (for 4D Write Pro, for example) using methods or variables from the host database.
More freedom and more power mean more responsibility, too, but this openness is still very practical and allows components to access functions of their host databases straightforwardly.
Don’t hesitate to share your impressions on the forum!