Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Java and Groovy are both "pass-by-value" languages.  That is, if you pass a value to a method and the method modifies it, you don't see a change in the calling scope.   

COM, on the other hand, supports both "pass-by-value" (or "byval") and "pass-by-reference" (or "byref").  When you call a method that accepts a "pass-by-reference" parameter, the method can modify the parameter value, and this will be reflected in the calling scope. 

Byref argument passing was always a favorite of C/C++ programmers, who often use the result of a method to pass exception information.  It was the default way to pass values in versions of Visual Basic through 6.  With the advent of modern try/catch exception handling, modifying values inside a method is generally considered bad programming practice.  Visual Basic (and COM) still supports byref, but byval is now defined as the default setting.  You should not have to deal with byref parameters often. That doesn't mean it will never happen, though. 

It shouldn't surprise you that Scriptom supports passing parameters by-reference, just in case you need it.   

There are actually two ways that values are passed by-reference.  For COM Events, which do not support returning values, the only way to pass back information is through a byref parameter.   That is all explained in the article, and it is actually pretty transparent.  You don't have to do anything special for it to work.  Your event handler can just change one of the arguments passed to it, and the caller sees the changed value. 

The other way that values are passed by reference is through an explicit method call you make.  This one is a little more complicated, but only a little.  Scriptom takes care of most of the scary details for you.

I order to pass a value by-reference, you first have to wrap it in a VariantByref object (org.codehaus.groovy.scriptom.VariantByref), like this:

  • No labels