UDF with no input parameters

Hi Adrian


If I create a UDF with no input parameters I get a #VALUE! result. I'm using CheckParameters with zero in the expected count. Not sure if it's a bug or I'm missing something - not currently a problem for me if it is a bug.

Kind regards, Bob

Indeed, checkparameters in delphi needs at least one parameter (in FlexCel .NET it would have been fine because there a null array is different from an array with 0 elements).

 
The workaround of course is easy, don't call CheckParameters if there aren't parameters. you can just do something like:

type
  TIndianaPI = class (TUserDefinedFunction)
  public
    constructor Create;
    function Evaluate(const arguments: TUdfEventArgs; const parameters: TFormulaValueArray): TFormulaValue; override;
  end;


constructor TIndianaPI.Create;
begin
  inherited Create('IndianaPI');
end;

function TIndianaPI.Evaluate(const arguments: TUdfEventArgs; const parameters: TFormulaValueArray): TFormulaValue;
var
  err: TFlxFormulaErrorValue;
begin
  //Instead of: if not CheckParameters(parameters, 0, err) then exit(err);
  if Length(parameters) <> 0 then exit(TFlxFormulaValue.ErrValue);

  Result := 3.2;
end;


But anyway, in case you want to use CheckParameters for consistency, I've just fixed it so it will work as expected with 0 parameters. Just email me to adrian@tmssoftware for an update.