optional and variant parameters in COM functions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

optional and variant parameters in COM functions

johncwhi
How do the Dolphin-generated COM classes and methods deal with optional
parameters in COM functions.  For example, I needed to use the MS Word
COM function Open, which applies to a Document object.  The Dolphin
wrapper method has this signature:

open: fileName confirmConversions: confirmConversions readOnly: readOnly
addToRecentFiles: addToRecentFiles passwordDocument: passwordDocument
passwordTemplate: passwordTemplate revert: revert writePasswordDocument:
writePasswordDocument writePasswordTemplate: writePasswordTemplate
format: format.

Everything but the fileName is an optional parameter in the actual COM
function.   I called the Dolphin wrapper like this:

docs open: s confirmConversions: false  readOnly: false
addToRecentFiles: false passwordDocument: '' passwordTemplate: ''
revert: false writePasswordDocument: '' writePasswordTemplate: ''
format: false.

That call worked, but I wonder if there may be a simpler way.   Could I
have passed "nil" for the optional parameters I didn't care about?  Or
0?

And finally, how does the 'Variant' type affect this whole thing?  I'm
not familiar with the 'Variant' type as wrapped by Dolphin.  Is there a
way to say something like "nil asVariant"?

TIA,

John Whittaker


Sent via Deja.com
http://www.deja.com/


Reply | Threaded
Open this post in threaded view
|

Re: optional and variant parameters in COM functions

Chris Double-2
[hidden email] writes:

> And finally, how does the 'Variant' type affect this whole thing?  I'm
> not familiar with the 'Variant' type as wrapped by Dolphin.  Is there a
> way to say something like "nil asVariant"?

There is 'VARIANT null' which specifies a variant with VT_NULL. But
for un-needed default parameters I think you migh want:

  VARIANT unspecified

  "Answer an instance of the receiver appropriate to use as an
  unspecified optional argument."

Chris.
--
http://www.double.co.nz/smalltalk


Reply | Threaded
Open this post in threaded view
|

Re: optional and variant parameters in COM functions

Don Rylander
In reply to this post by johncwhi
John,
<[hidden email]> wrote in message news:94hr01$sb6$[hidden email]...
> How do the Dolphin-generated COM classes and methods deal with optional
> parameters in COM functions.  For example, I needed to use the MS Word
[snip]
> That call worked, but I wonder if there may be a simpler way.   Could I
> have passed "nil" for the optional parameters I didn't care about?  Or
> 0?

Your best bet is to do a bit of experimentation with what the optional
parameters will accept.  In my experience, your intuition about nil and 0 is
correct; in most cases they'll work nicely.

I also tend to wrap the methods with ones I'd use more often (like providing an
#open: method that just passes the filename with the correct default parameters
to the generated method).

One caveat: if you change the generated method in a way that you'd like to
preserve, be sure to remove it from the **auto-generated** category.  That will
prevent it from being overwritten should you decide to regenerate the
interface.

Don