Raccolta e oggetto HDI 4DVP nelle funzioni personalizzate
Le funzioni personalizzate sono una potente caratteristica di 4D View Pro che consente di estendere le sue funzionalità e di eseguire calcoli o operazioni personalizzate in base alle vostre esigenze specifiche. Ora è possibile accettare collezioni come parametri di funzioni personalizzate contenenti valori di intervalli di celle specificati dall’utente.
Gestione delle raccolte
Creazione della funzione personalizzata
Per prima cosa, creeremo la funzione chiamata da 4D View Pro. Questa funzione, chiamata _averageNonZeroValues(), accetta un parametro di raccolta ed è definita in questo modo:
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
Abilitare la funzione personalizzata in 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
Gestione degli oggetti
- Stabilire una funzione destinata all’esecuzione da parte di 4D View Pro per eseguire il calcolo.
- Formulare un oggetto per specificare le opzioni della funzione personalizzata.
Per questo esempio, completeremo la classe CustomFunctionCreator .
Creazione della funzione personalizzata
Per prima cosa, creeremo la funzione chiamata da 4D View Pro. Questa funzione, chiamata _modifiedProperties(), accetta un parametro oggetto ed è definita in questo modo:
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 ""
Abilitazione della funzione personalizzata in 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
Dichiarazione della funzione personalizzata
L’ultimo passo consiste nel chiamare VP SET CUSTOM FUNCTIONS sull’evento“on Load” del form, utilizzando le funzioni averageNonZeroValues() e 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
Ora, avete 2 nuove funzioni utilizzabili nell’area 4D View Pro:
- “MY_AVERAGENONZEROVALUES”:
- “MIE_MODIFICHE”:
In conclusione, l’uso di funzioni personalizzate in 4D View Pro eleva la funzionalità del foglio di calcolo a nuovi livelli, consentendo calcoli e operazioni su misura. Per ulteriori informazioni, consultare la nostra documentazione.