Parameters

This topic discusses passing parameters to Interface members using both Positional and Named Methods.

Parameters, assignment values, and return values must be passed as Variant variables.

Passing parameters to an Interface Method or Property is performed in a similar way to conventional parameter passing techniques - the terminology is really just a little different, and with COM, everything is done using Variant variables.

First, let's look at the syntax used to specify parameter-passing modes for Interface Methods and Properties, and examine the various options and their effects on the parameters.  The actual parameter portion of a member definition are shown in bold in the following syntax definition block:

MEMBER {CALL | GET | SET | LET} membername <dispid> ( [[OPTIONAL [IN | OUT | _

    INOUT]] paramname <dispid> [AS type] [,...]] ) [AS {vartype | interface}]

The IN, OUT and INOUT clauses work similarly to the BYVAL and BYREF parameter passing modes.  That is, the Object will not modify parameters marked as IN, but the Object can alter parameters marked as OUT or INOUT.  The easiest way to remember this is to remember that the Object can output data through the parameter.

To set the value of a Variant variable to pass to an Interface member, simple assign the value to the Variant as is done with any other standard data type, or use the LET statement.  For example, the two assignment lines in the following code are equivalent:

DIM vVnt AS VARIANT

...

LET vVnt = "PowerBASIC!"

vVnt = "PowerBASIC!"

It should be noted that passing an uninitialized Variant as a parameter to an Interface member is not recommended, since the Interface member may not be designed to cope with it.  It is recommended that Variants at least be set to zero ( numeric assignment of 0) or null ( string assignment of an empty string) before passing the Variant parameter.

The AS type clause specifies the actual type of data that is stored in the Variant variable passed as a parameter.  For example, if the parameter is of type STRING, the Variant parameter variable should contain string data.

If the OPTIONAL clause is present, the parameter can be omitted from the parameter list.

 

See Also

COM Programming Introduction

Positional and Named parameter passing

Return data