This topic discusses receiving parameters back from Interface member Methods and Property calls, translating the Variant data types to native PowerBASIC data types, and handling the return of Interfaces.
Parameters, assignment values, and return values must be passed as Variant variables.
Both the OBJECT GET statement (for Properties) and the OBJECT CALL statements (Methods) return values to the calling code. These return values must be received into a Variant variable. Therefore, before the data can be processed with normal BASIC statements, the Variant data must be converted to a suitable native data type.
PowerBASIC provides the VARIANT# function to convert numeric values held in a Variant variable, and the VARIANT$ function to convert string data held in a Variant variable.
The VARIANTVT function is used to determine the type of data held in a Variant, but any comparisons should use equates rather than hard-coded values. See VARIANTVT for more information.
Interface members can also return Interface references that can be used to access other COM Interfaces. These return values should be directly assigned to an object variable before the Interface they reference can be accessed. This is best shown by example, so we'll briefly reexamine a portion of the Microsoft Word™ code we presented a little earlier:
FUNCTION PBMAIN()
DIM oWordApp AS WordApplication ' Application Interface
DIM oWordDoc AS WordDocument ' Document Interface
DIM vVnt AS VARIANT
DIM sResult AS STRING
...
LET vVnt = 0
OBJECT CALL oWordApp.Documents.Add TO vVnt
LET oWordDoc = vVnt
LET vVnt = 0
OBJECT GET oWordApp.Documents.Count TO vVnt
sResult = "MSWORD has " + FORMAT$(VARIANT#(vVnt)) + _
" Files loaded!"
...
The relevant portions are underlined. The Method oWordApp.Documents.Add returns an Interface reference (of the type WordDocument), which the code receives back in the Variant vVnt. This is then assigned to the object variable oWordDoc and this Interface reference is used to access the oWordApp.Documents.Count Property of the WordDocument Interface.
When an Interface member returns an Interface reference, this is sometimes referred to as interface nesting.
See Also