The OnUserFunction callback lets application code evaluate
custom or otherwise unsupported worksheet functions during
Calculate. Assign it on TXLSWorkbook or
TXLSXWorkbook before calling Calculate.
Syntax
type
TXLSUserFunctionEvent = procedure(
Sender: TObject;
const FunctionName: WideString;
const Args: Variant;
var Value: Variant;
var Handled: Boolean) of object;
property OnUserFunction: TXLSUserFunctionEvent;
Arguments
| FunctionName |
The function name from the formula text. |
| Args |
A zero-based Variant array containing evaluated
argument values. For zero-argument functions this value is
Null. |
| Value |
Set this to the function result. |
| Handled |
Set to True when the callback supplies
a result. Leave False to keep the normal unsupported
function behavior. |
Example
procedure TForm1.WorkbookUserFunction(Sender: TObject;
const FunctionName: WideString; const Args: Variant;
var Value: Variant; var Handled: Boolean);
begin
if SameText(FunctionName, 'DOUBLEPLUS') then
begin
Value := Double(Args[0]) * 2 + Double(Args[1]);
Handled := True;
end;
end;
Workbook.OnUserFunction := WorkbookUserFunction;
Value := Workbook.Calculate('=DOUBLEPLUS(A1;5)');
See also