How Do I Know Which Type I Have?
A common problem is deciding what capabilities an object really has, after you receive it from a method. By observing the code completion in Java IDE, you can discover the base interface of an object returned from a method. You will notice that loadComponentFromURL() returns a com.sun.star.lang.XComponent.
By pressing Alt + F1 in the NetBeans IDE you can read specifications about the interfaces and services you are using.
However, methods can only be specified to return one interface type. The interface you get from a method very often supports more interfaces than the one that is returned by the method (especially when the design of those interfaces predates the availability of multiple-inheritance interface types in UNO). Furthermore, the interface does not tell anything about the properties the object contains.
Therefore you should use this manual to get an idea how things work. Then start writing code, using the code completion and the API reference.
In addition, you can try the InstanceInspector, a Java tool which is part of the OpenOffice.org SDK examples. It is a Java component that can be registered with the office and shows interfaces and properties of the object you are currently working with.
In OpenOffice.org Basic, you can inspect objects using the following Basic properties.
sub main oDocument = thiscomponent msgBox(oDocument.dbg_methods) msgBox(oDocument.dbg_properties) msgBox(oDocument.dbg_supportedInterfaces) end sub
For a complex object, these msgBox calls will run right off the screen. Try the following, instead:
sub main oDocument = thiscomponent GlobalScope.BasicLibraries.LoadLibrary( "Tools" ) Call Tools.WritedbgInfo(oDocument) end sub
This produces a new Writer document, containing the retrieved information.
|Content on this page is licensed under the Public Documentation License (PDL).|