Using the Formula Wizard to Add Your Own Functions

The formula wizard and its features are among the most important and powerful capabilities of the Designer. Using a special List & Label VCL component, you can also integrate fully customized functions into the Designer.

To add a new function, insert this component on a form in the development environment. You can now set the necessary parameters in the Properties window of this component:

 

Property

Description

Name

The unique name of the designer function.

Description

An additional description of the function for the formula wizard.

GroupName

The group in which the function is displayed in the formula wizard.

Visible

Indicates whether or not the function will be displayed in the wizard.

MinimumParameters

The minimum number of parameters. Permissible values between 0 and 4.

MaximumParameters

The maximum number of parameters. Here too, permissible values between 0 and 4. The value must be equal to or greater than the minimum number. Increasing the number results in optional parameters.

Parameter1 – 4

The configuration for each of the four parameters can be customized.

 

Type

The data type of the parameter.

 

Description

A description of the parameter for the tooltip help in Designer.

ResultType

The data type of the return value.

 

Using the properties, you can customize the configuration of the new Designer function. In order to bring the function to life, you have to handle the event OnEvaluateFunction. Using the event arguments, you gain access to the parameters entered by the user. For example, to return the Roman numeral, use the following lines:

Delphi:

procedure TDesExtForm.RomanNumberEvaluateFunction(Sender: TObject;
       var ResultType: TLl29XFunctionParameterType;
       var ResultValue: OleVariant;
       var DecimalPositions: Integer; const ParameterCount: Integer;
       const Parameter1, Parameter2, Parameter3, Parameter4: OleVariant);
begin
       ResultValue:=ToRoman(Parameter1);
end;

Two additional events also give you the option to further modify the function. OnCheckFunctionSyntax lets you perform a syntax check. Here you can check the data types of the parameters and, for example, make sure the parameters fall within a certain range. Using OnParameterAutoComplete you can define several suggested values for the AutoComplete feature of the formula wizard.