Hi,
i am not sure about which tutorial you are talking but it is quite simple.
As the reference documentation of an addin
(http://api.openoffice.org/docs/common/ref/com/sun/star/sheet/AddIn.html)
describes, optional parameters can be defined as a sequence of Any and
that only as the last parameter.
From the reference docu:
"...
any[]
for varying parameters. Only the last parameter of a function may
have this type. It will be filled with the remaining arguments of the
function call that were not used for the previous parameters. Each
element of the sequence will be filled as in the case of any above.
..."
In NetBeans you have to define the last parameter as an Object[] array
which is equal to a sequence of any. Keep in mind that our NB Add-In
wizard maps the available types directly to Java according the Java-UNO
type mapping.
Example:
IDL:
###
module com { module example {
interface XTestAddIn {
/// used to set an add-in locale for formatting reasons for example
[optional] interface ::com::sun::star::lang::XLocalizable;
string testFunction([in] long param1, [in] string param2, [in]
sequence< any > optionalParams);
};
}; };
###
Java:
###
public String testFunction(int param1, String param2, Object[]
optionalParams)
{
StringBuffer ret = new StringBuffer("Result: ");
ret.append("Param1="+param1);
ret.append(" Param2="+param2);
if (optionalParams.length > 0) {
ret.append(" Number of optional
parameter="+optionalParams.length);
for (Object o: optionalParams) {
ret.append(" optionalparam="+o.toString());
}
}
return ret.toString();
}
###
Juergen
Irné Barnard wrote:
I'm trying to port one of my Basic macros for custom calc formulas to an
UNO extension. So I tried to use NetBeans. Unfortunately some of the
functions have optional parameters. I know that Java doesn't have such a
thing as optional parameters. Does anyone know how I could do this?
Simply setting the parameter type to any as shown on the tutorials will
produce an error while compiling.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]