Converting COM code to PowerBASIC

The default Interface member trap

When porting Visual Basic code to PowerBASIC (or other languages such as Delphi), it is sometimes necessary to explicitly add a member name to the ported code in PowerBASIC.  This is required because Visual Basic uniquely supports a "short-hand" default Interface member that allows the name of the default Method to be omitted from the VB code.

For example, the following portions of VB code are equivalent:

var = Application.Documents(1)

var = Application.Documents.Item(1)

In the above code, the .Item() member is the default Property of the Documents Interface, and the first line of code takes advantage of VB's default member feature, allowing the name of the default Property to be omitted from the statement.

Usually, omitting a member name in code translated to PowerBASIC will not work correctly - it could produce a compile-time error or a run-time failure in the OBJECT statement.  The type of error will depend on the exact definition of the Interface(s) being used.

In such cases, carefully study the COM component's documentation to establish if a named Interface member is missing from the OBJECT statement.  In the case of Visual Basic, it is usually the .Item Property that is omitted.

Delphi does not support default Interface members, so Delphi COM code is less likely to cause these particular kinds of code conversion problems.

VB Method call syntax

In PowerBASIC, all Method and Property calls to Interface members must be performed with the OBJECT statement.  However, Visual Basic permits a slightly less wordy syntax.  For example:

Set Var = GetObject("progid")

Var.execute

The equivalent PowerBASIC syntax would look something like this:

LET Var = DISPATCH IN "progid"

OBJECT CALL Var.execute

 

See Also

COM Programming Introduction

The PowerBASIC COM Browser