Difference between revisions of "Documentation/DevGuide/FirstSteps/How do I know Which Type I Have?"

From Apache OpenOffice Wiki
Jump to: navigation, search
Line 1: Line 1:
{{FirstSteps|FirstSteps=block|PrevNext=block|Prev=Element Access|Next=Example: Hello Text, Hello Table, Hello Shape}}
+
{{FirstSteps|FirstSteps=block|PrevNext=block|Prev=Documentation/APIGuide/FirstSteps/Element Access|Next=Documentation/APIGuide/FirstSteps/Example: Hello Text, Hello Table, Hello Shape}}
 +
{{DISPLAYTITLE: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.
 
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 <code>loadComponentFromURL()</code> returns a [http://api.openoffice.org/docs/common/ref/com/sun/star/lang/XComponent.html com.sun.star.lang.XComponent].  
 
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 <code>loadComponentFromURL()</code> returns a [http://api.openoffice.org/docs/common/ref/com/sun/star/lang/XComponent.html com.sun.star.lang.XComponent].  

Revision as of 07:49, 21 June 2007

Template:FirstSteps

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 uses 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
Personal tools