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

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Robot: Changing Category:First Steps)
m
(9 intermediate revisions by 5 users not shown)
Line 4: Line 4:
 
|NextPage=Documentation/DevGuide/FirstSteps/Example: Hello Text, Hello Table, Hello Shape
 
|NextPage=Documentation/DevGuide/FirstSteps/Example: Hello Text, Hello Table, Hello Shape
 
}}
 
}}
 +
{{Documentation/DevGuideLanguages|Documentation/DevGuide/FirstSteps/{{SUBPAGENAME}}}}
 
{{DISPLAYTITLE:How Do I Know Which Type I Have?}}
 
{{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 <idl>com.sun.star.lang.XComponent</idl>.  
+
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 <tt>loadComponentFromURL()</tt> returns a <idl>com.sun.star.lang.XComponent</idl>.  
  
 
By pressing Alt + F1 in the NetBeans IDE you can read specifications about the interfaces and services you are using.
 
By pressing Alt + F1 in the NetBeans IDE you can read specifications about the interfaces and services you are using.
Line 12: Line 13:
 
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.  
 
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.
+
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 {{PRODUCTNAME}} 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 addition, you can try the InstanceInspector, a Java tool which is part of the {{PRODUCTNAME}} 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.
Line 18: Line 19:
 
In {{PRODUCTNAME}} Basic, you can inspect objects using the following Basic properties.
 
In {{PRODUCTNAME}} Basic, you can inspect objects using the following Basic properties.
  
   <source lang="vb">
+
   <source lang="oobas">
 
   sub main
 
   sub main
 
     oDocument = thiscomponent
 
     oDocument = thiscomponent
Line 26: Line 27:
 
   end sub
 
   end sub
 
   </source>
 
   </source>
 +
<br />
 +
For a complex object, these <tt>msgBox</tt> calls will run right off the screen. Try the following, instead:
 +
 +
  <source lang="oobas">
 +
  sub main
 +
    oDocument = thiscomponent
 +
    GlobalScope.BasicLibraries.LoadLibrary( "Tools" )
 +
    Call Tools.WritedbgInfo(oDocument)
 +
  end sub
 +
  </source>
 +
 +
This produces a new Writer document, containing the retrieved information.
 +
 +
 +
 +
Using these DBG properties is a very crude method to discover the contents of an API objects. Use instead <b>[[Extensions_development_basic#Xray_tool|Xray tool]] or [http://extensions.services.openoffice.org/project/MRI MRI tool]</b>.
  
 
{{PDL1}}
 
{{PDL1}}
  
[[Category:Documentation/Developers Guide/First Steps]]
+
[[Category:Documentation/Developer's Guide/First Steps]]

Revision as of 06:38, 1 May 2016



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.


Using these DBG properties is a very crude method to discover the contents of an API objects. Use instead Xray tool or MRI tool.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages