Restrictions on coding

There are some elements that you cannot use in your code when you plan to deploy a user object as a COM component.

No overloaded functions

COM does not support overloaded functions in an interface to a COM object. Each function in the user object (and its ancestors) must have a unique name. PowerBuilder COM objects have a single interface, and multiple functions with the same name but different signatures would require multiple interfaces.

How ancestor variables and ancestor functions are represented

When you generate a PowerBuilder COM object from a descendent user object, the public instance variables and functions of both the ancestor and the descendant are represented in the COM object. The fact that some of the component methods were derived from the ancestor object is transparent. Because of the restriction on overloaded functions described above, functions in descendent objects can override functions in the ancestor, but they cannot overload them.

Datatypes for arguments and return values

The methods associated with a nonvisual object that you deploy as a COM object can take arguments that use the following datatypes:

COM component methods cannot take arguments or return values that use PowerBuilder structures or the Any datatype. Functions defined on a PowerBuilder nonvisual object that take an Any variable as an argument or return an Any variable can be called from code that is local to that object; however, these functions cannot be accessed by clients or other COM components.

The arguments to a component method cannot include visual objects (such as windows or menus) or most system types (such as the Transaction object or the DataStore object). The only system type supported is the ResultSet object.

The return value of a component method can be of any standard datatype. The return value can also be a custom class (nonvisual) user object.

COM validation

If you are designing a custom class user object that you plan to deploy as a COM component, you can have PowerBuilder warn you when you use code elements that are not valid in COM.

COM validation checks for overloaded functions and checks public instance variables and public functions for system types, visual types, structures, and Any variables.

In the User Object painter, make sure the Design>COM Validation menu item is checked. When you save the object, the Output window lists warnings such as the following:

Information C0197: Component Validation
Warning C0198: illegal COM type: 'any' arg type for function: 'of_badfunc' 
Warning C0198: illegal COM type: 'window' arg type for function: 'of_badfunc' 

Validation is associated with the object you are editing, not with the User Object painter. When you reopen an object, it has the same validation state as when you closed it. New COM objects are created with COM validation checked.