Optional Arguments

Java, C++, C#, Delphi, ??? - Using the UNO bridges

Optional Arguments

Postby saleem145 » Tue Dec 18, 2012 3:36 pm

Hello,

I would like to write a function which takes in four arguments. Each of the argument is a two dimensional range of cells. But they are optional. My question is what should my idl and xcu file look like. And the function prototype. I am developing a C++ add in.

Thanks,

Saleem
OpenOffice 3.4.0
Mac OS X 10.5.8
saleem145
 
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

Re: Optional Arguments

Postby Charlie Young » Tue Dec 18, 2012 5:52 pm

saleem145 wrote:Hello,

I would like to write a function which takes in four arguments. Each of the argument is a two dimensional range of cells. But they are optional. My question is what should my idl and xcu file look like. And the function prototype. I am developing a C++ add in.

Thanks,

Saleem


Optional arguments are specified as any in the idl file, and require no special consideration in the CalcAddin.xcu.

Here's the idl for one I happen to have.

Code: Select all   Expand viewCollapse view
string cDraw( [in] sequence< sequence< any > > dims, [in] string ShapeName, [in] any FillSpecs, [in] any ShapeText, [in] ::com::sun::star::beans::XPropertySet docProps);


In the program then, FillSpecs and ShapeText are optional. In my example here, FillSpecs might typically be an array or a single value, and I check it in the code like

Code: Select all   Expand viewCollapse view
if(FillSpecs.getValueTypeName() == OUString(RTL_CONSTASCII_USTRINGPARAM("[][]any"))) {
      ---- do array stuff
) else (FillSpecs.getValueTypeName() == OUString(RTL_CONSTASCII_USTRINGPARAM("double"))) {
     ... do single value stuff
}


One thing to note with this though is that if you pass a CellRange in this fashion, you only get the ranges dataArray , but if you specify it to be an XCellRange in the idl and the code, then you also have access to the cell formats and such, but then it can't be optional.

The ValueTypeName for an omitted optional argument is "void."
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Volunteer
 
Posts: 1559
Joined: Fri May 14, 2010 1:07 am


Return to External Programs

Who is online

Users browsing this forum: No registered users and 1 guest