On-Change script
This kind of a script is bound to a single data field and it is executed AFTER the value of this data field has changed. The purpose of the on-change script is to react to a data field change - for example by calculating and setting a value to another data field. Note that changing a value of a data field in a script can trigger an on-validate and/or an on-change script for that field. To avoid this effect, see Disabling events in scripts.
Example :
The following script checks the DBH/height ratio of a tree and warns the user if it is out of interval <0.6; 1.6>. The script takes values of the fields "DBH_mm' and "Height_m' as its input. Since there is no way to know which of these values will be measured last, there should be two On-Change scripts, one for each of these fields. The best solution here is to write only one On-Change script common to both fields, assign it to one field and reference it in the other.
The script assigned to the "DBH_mm' field:
// ---- Trees.DBH_mm On-Change script
var
dbh, height: variant;
ratio: double;
begin
dbh := Trees['DBH_mm'];
height := Trees['Height_m'];
if (height <> null) and (dbh <> null) then
begin
if (height > 0) then
begin
ratio := (dbh / 10) / height
if (ratio < 0.6) or (ratio > 1.6) then
ShowMessage (Format('Warning! Slenderness ratio (%0.2f) is out of <0.6;1.6>.', [ratio]));
end
else
ShowMessage('Warning! Tree has zero height.');
end;
end.
The same script referenced in the "Height_m" field:
// ---- Trees.Height_m On-Change script
// {$REF_ATTRIBUTE Trees.DBH_mm}
See also:
Field-Map script types overview; On-Validate scripts; On-Change scripts; On-Demand scripts; Layer scripts; Global scripts; Field-Map script types; Writing scripts in Field-Map
© 2024 IFER-Monitoring and Mapping Solutions