Skip to main content
Version: 20 R6

VP SET CUSTOM FUNCTIONS

VP SET CUSTOM FUNCTIONS ( vpAreaName : Text ; formulaObj : Object )

ParameterTypeDescription
vpAreaNameText->4D View Pro area form object name
formulaObjObject->Formula object

Description

The VP SET CUSTOM FUNCTIONS command designates the 4D formulas that can be called directly from 4D View Pro formulas. Because custom functions are not stored in the document,VP SET CUSTOM FUNCTIONS must be executed in the On Load form event.

The formulas specified by VP SET CUSTOM FUNCTIONS appear in a pop-up menu when the first letter of their name is entered. See the Formulas and Functions page.

If VP SET CUSTOM FUNCTIONS is called multiple times for the same area, in the same session, only the last call is taken into account.

Pass the name of the 4D View Pro area in vpAreaName. If you pass a name that does not exist, an error is returned.

In the formulaObj parameter, pass an object containing the 4D formulas that can be called from 4D View Pro formulas as well as additional properties. Each customFunction property passed in formulaObj becomes the name of a function in the 4D View Pro area.

PropertyTypeDescription
<customFunction>ObjectCustom function definition. <customFunction> defines the name of the custom function to display in 4D View Pro formulas (no spaces allowed)
formulaObject4D formula object (mandatory). See the Formula command.
parametersCollection of objectsCollection of parameters (in the order they are defined in the formula). For more information, please refer to the Parameters section.
[ ].nameTextName of parameter to display in 4D View Pro
[ ].typeNumberType of the parameter. Supported types:
  • Is Boolean
  • Is collection
  • Is date
  • Is Integer
  • Is object
  • Is real
  • Is text
  • Is time
  • type can be omitted or the default value (-1) can be passed (except when at least one parameter is of collection type, in which case parameter's type declaration is mandatory).
    If type is omitted or -1, the value is automatically sent with its type, except date or time values which are sent as an object. If type is Is object, the object is sent in a .value property. See Parameters section.
    summaryTextFormula description to display in 4D View Pro
    minParamsNumberMinimum number of parameters
    maxParamsNumberMaximum number of parameters. Passing a number higher than the length of parameters allows declaring "optional" parameters with default type

    WARNING

    • As soon as VP SET CUSTOM FUNCTIONS is called, the methods allowed by the VP SET ALLOWED METHODS command (if any) are ignored in the 4D View Pro area.
    • As soon as VP SET CUSTOM FUNCTIONS is called, the functions based upon SET TABLE TITLES and SET FIELD TITLES commands are ignored in the 4D View Pro area.

    Example

    You want to use formula objects in a 4D View Pro area to add numbers, retrieve a customer's last name and gender and the company's peak month:

    Case of
    :(FORM Event.code=On Load)

    var $o : Object
    $o:=New object

    // Define "addnum" function from a method named "addnum"
    $o.addnum:=New object
    $o.addnum.formula:=Formula(addnum)
    $o.addnum.parameters:=New collection
    $o.addnum.parameters.push(New object("name";"num1";"type";Is Integer))
    $o.addnum.parameters.push(New object("name";"num2";"type";Is Integer))

    // Define "ClientLastName" function from a database field
    $o.ClientLastName:=New object
    $o.ClientLastName.formula:=Formula([Customers]lastname)
    $o.ClientLastName.summary:="Lastname of the current client"

    // Define "label" function from a 4D expression with one parameter
    $o.label:=New object
    $o.label.formula:=Formula(ds.Customers.get($1).label)
    $o.label.parameters:=New collection
    $o.label.parameters.push(New object("name";"ID";"type";Is Integer))

    // Define "AverageValues" function from a method named "AverageValues"
    $o.AverageValues:=New object
    $o.AverageValues.formula:=Formula(AverageValues)
    $o.AverageValues.parameters:=New collection
    $o.AverageValues.parameters.push(New object("name";"Mycollection";"type";Is collection))

    // Define "Title" function from a variable named "Title"
    $o.Title:=New object
    $o.Title.formula:=Formula(Title)

    VP SET CUSTOM FUNCTIONS("ViewProArea";$o)

    End case

    See also

    4D functions
    VP SET ALLOWED METHODS
    4D View Pro: enhancement of custom functions (blog post)