Excel UDF with optional Parameter

Add-in Express™ Support Service
That's what is more important than anything else

Excel UDF with optional Parameter
 
Frank Jepsen




Posts: 14
Joined: 2016-07-05
Hi,

I wanted to create an UDF with optional parameter.
In VBA it looked like this
Function AbstV(MatEP As String, MatLi As String, Optional WithPedigree As Boolean = True) As String

But in Delphi I could not set the "optional" checkbox in Parameter-Flags dialog in ridl-designer. It looks like optional is only allowed in last parameter. But that is Result. I finally changed the ridl-source to
    HRESULT _stdcall AbstV([in] BSTR BarcodeEP, [in] BSTR BarcodeMList, [in, optional, defaultvalue(False)] VARIANT_BOOL WithPedigree, [out, retval] VARIANT* Result);


This seems to work as expected but looks somewhat wrong.

Greetings
Frank
Posted 27 Jul, 2016 10:48:51 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Frank,

Delete Result, set "optional" and create Result anew. This works for us.


Andrei Smolin
Add-in Express Team Leader
Posted 28 Jul, 2016 06:22:27 Top
Frank Jepsen




Posts: 14
Joined: 2016-07-05
Andrei Smolin writes:
Delete Result, set "optional" and create Result anew. This works for us.

Or write it in the code like I did.

Looks like a flaw in Delphi. If the last parameter is marked with [retval] it should be ignored.

Thanks confirming.
Frank
Posted 28 Jul, 2016 07:16:21 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
You are welcome!


Andrei Smolin
Add-in Express Team Leader
Posted 28 Jul, 2016 07:46:25 Top