TdxSpreadSheetFunction Type
The procedural type for implementation routines of spreadsheet function signatures.
Declaration
TdxSpreadSheetFunction = procedure(Sender: TdxSpreadSheetFormulaResult; const AParams: TdxSpreadSheetFormulaToken);
Parameters
Name | Type |
---|---|
Sender | TdxSpreadSheetFormulaResult |
AParams | TdxSpreadSheetFormulaToken |
Remarks
A function signature’s implementation routine:
Evaluates accepted parameters for possible errors and extracts the parameters from a function call token (via the AParams parameter) in a parsed formula expression.
Uses the extracted parameters to perform calculations.
Populates the result token (via the Sender parameter) with one or more calculated results according to the function signature’s ResultKind field value.
The following code example shows how to implement a function that calculates the area of a triangle (S) given two sides (a and b) and the angle (γ, in degrees) between them according to the formula: S = 0.5 * a * b * sin γ.
procedure functionTriangleArea(Sender: TdxSpreadSheetFormulaResult; const AParams: TdxSpreadSheetFormulaToken);
var
P1, P2, P3: Variant; // The function accepts three numeric parameters
begin
if(Sender.GetParamsCount(AParams) <> 3) then // The function has three mandatory parameters
Sender.SetError(ecValue) // The function inserts the #VALUE! error code into the result token instead of a calculated value if the parameter count is incorrect
else
// The function consecutively extracts the three numeric values from a formula call token into the P1, P2, and P3 temporary variables
if(Sender.ExtractNumericParameter(P1, AParams, 0) and
Sender.ExtractNumericParameter(P2, AParams, 1) and
Sender.ExtractNumericParameter(P3, AParams, 2)) then
// The function calculates the area of a triangle if all parameters are successfully extracted as numeric values
Sender.AddValue(0.5 * P1 * P2 * SIN(P3 * Pi / 180)); // Inserts the calculated result into the result token
end;
A function signature’s Proc field references the TdxSpreadSheetFunction procedural type.