Collection et objet HDI 4DVP dans les fonctions personnalisées
Les fonctions personnalisées sont une caractéristique puissante de 4D View Pro qui vous permet d’étendre ses fonctionnalités et d’effectuer des calculs ou des opérations personnalisés adaptés à vos besoins spécifiques. Vous pouvez désormais accepter des collections en tant que paramètres de fonctions personnalisées contenant des valeurs provenant de plages de cellules spécifiées par l’utilisateur.
Gestion des collections
Création d’une fonction personnalisée
Tout d’abord, nous allons créer la fonction appelée par 4D View Pro. Cette fonction, appelée _averageNonZeroValues(), prend un paramètre de collection et est définie comme suit :
Function _averageNonZeroValues($values : Collection) : Real
// Average of the non zero and non null values in the range
// Sum of all the collection values
var $total:=$values.flat().sum()
// Calculates the number of cells containing a value other than 0 or NUll
var $NonZeroValueNumber : Integer:=$values.flat().count()-$values.flat().countValues(0)
// Returns the calculation result to be displayed in the cell
return $NonZeroValueNumber>0 ? $total/$NonZeroValueNumber : 0
Activer la fonction personnalisée dans 4D View Pro
Function averageNonZeroValues()->$customFunction : Object
var $this : Object
$customFunction:={}
$this:=This // Capture This for the formula
// formula that will be called when the custom function is used in the spreadsheet
$customFunction.formula:=Formula($this._averageNonZeroValues($1))
// If a parameter is of collection type, the declaration of the custom function parameters is mandatory
$customFunction.parameters:=[{name: "Values"; type: Is collection}]
// Summary of the custom function using in the autocomplete popup
$customFunction.summary:="Returns the average of non zero values"
// Expected number of parameters
$customFunction.minParams:=1
$customFunction.maxParams:=1
Gestion des objets
- Établir une fonction destinée à être exécutée par 4D View Pro pour effectuer le calcul.
- Formuler un objet pour spécifier les options de la fonction personnalisée.
Pour cet exemple, nous compléterons la classe CustomFunctionCreator .
Création d’une fonction personnalisée
Tout d’abord, nous allons créer la fonction appelée par 4D View Pro. Cette fonction, appelée _modifiedProperties(), prend un paramètre objet et est définie comme suit :
Function _modifiedProperties($object: Object) : Text
// Comparison between the properties in the Form.people object and the properties in the spreadsheet
var $myObject : Object:=$object.value
// Search the object attributes modified between the people data and the data in the spreadsheet
For each ($property; $myObject)
// comparison between the object returned by the spreadsheet and the Form.people object
If ($myObject[$property]#Form.people[$property])
return "Data modified."
End if
End for each
return ""
Activer la fonction Custom dans 4D View Pro
Function modifiedProperties()->$customFunction : Object
var $this : Object
$customFunction:={}
$this:=This // Capture This for the formula
// formula that will be called when the custom function is used in the spreadsheet
$customFunction.formula:=Formula($this._modifiedProperties($1))
// If a parameter is of collection type, the declaration of the custom function parameters is mandatory
$customFunction.parameters:=[{name: "Values"; type: Is object}]
// Summary of the custom function using in the autocomplete popup
$customFunction.summary:="Returns a message when the object is modified by the user"
// Expected number of parameters
$customFunction.minParams:=1
$customFunction.maxParams:=1
Déclaration de la fonction personnalisée
La dernière étape consiste à appeler VP SET CUSTOM FUNCTIONS sur l’événement« on Load » du formulaire en utilisant les fonctions averageNonZeroValues() et modifiedProperties() :
Case of
: (FORM Event.code=On Load)
var $customFunctions:={}
// Declaration of authorized custom functions in the 4D View Pro area
var $creator:=cs.CustomFunctionsCreator.new()
$customFunctions.MY_AVERAGENONZEROVALUES:=$creator.averageNonZeroValues()
$customFunctions.MY_MODIFICATIONS:=$creator.modifiedProperties()
VP SET CUSTOM FUNCTIONS("ViewProArea"; $customFunctions)
End case
Vous disposez maintenant de 2 nouvelles fonctions utilisables dans votre espace 4D View Pro :
- « MY_AVERAGENONZEROVALUES » :
- « MES_MODIFICATIONS » :
En conclusion, l’utilisation de fonctions personnalisées dans 4D View Pro élève la fonctionnalité des feuilles de calcul à de nouveaux sommets, en permettant des calculs et des opérations sur mesure. Veuillez consulter notre documentation pour de plus amples informations.