When you use collections with a member method that needs a callback method, many of you have asked us for a more straightforward way.
You asked; we delivered!
Starting with 4D v19 R6, 4D allows you to use a formula to define a callback in the collection member functions, the EXECUTE METHOD IN SUBFORM, CALL FORM, and CALL WORKER commands. If you can reduce your code to a simple expression, you can pass it directly into the formula without using a method.
formula in COLLECTIoN
You can now use formula as callback in the members methods: .every(), .filter(), .find(), .findIndex(), .map(), .orderByMethod(), .reduce(), .some(), .sort()
For example, if you want to filter the collection to find all the members greater than 0, you can do it on one line:
$result:=$c.filter(Formula($1.value>0))
As you can see above, to be more simple and readable, we make the $1.result optional in the formulas.
Of course, you can always use the code:
$c:=New collection
$c.push(1;-5; -3; -1;3; -4; -6; -2;10)
$result:=$c.filter("NumberGreaterThan0")
but you can use formula too to refer to a method and so benefit from the code completion to find your method name, and take advantage of automatic renaming if you change the name of your method:
$c:=New collection
$c.push(1;-5; -3; -1;3; -4; -6; -2;10)
$result:=$c.filter(Formula(NumberGreaterThan0))
with the NumberGreaterThan0 method:
#DECLARE ($param:Object)
$param.result:=$param.value>0
formula in commands
You can use a formula to define a callback in the EXECUTE METHOD IN SUBFORM, CALL FORM, and CALL WORKER commands.
As for the collections, you can use expressions without having to create a method:
// Close the windows in the context of the form
CALL FORM($windows;formula(CANCEL))
or refer to a method with one of these 2 ways:
EXECUTE METHOD IN SUBFORM("Subform"; Formula(UpdateField))
or
EXECUTE METHOD IN SUBFORM("Subform"; "UpdateField")
Try all these new features with the HDI above, and do not hesitate to give your feedback on the forum!