Difference between revisions of "Documentation/DevGuide/ProUNO/CLI/Lifetime Management and Obtaining Interfaces"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (1 revision(s))
m (Robot: Changing Category:Professional UNO)
Line 43: Line 43:
  
 
{{PDL1}}
 
{{PDL1}}
[[Category: Professional UNO]]
+
 
 +
[[Category:Documentation/Developers Guide/Professional UNO]]

Revision as of 15:09, 8 May 2008



The CLR is similar to the Java runtime in that it keeps track of the object's lifetime rather then leaving the task to the developer. Once an object is no longer referenced (unreachable), the CLR deletes that object. Therefore, reference counting, as used in C++, is not necessary. Hence com.sun.star.uno.XInterface:acquire and com.sun.star.uno.XInterface:release are not needed.

XInterface has a third method, queryInterface, which is used to query an object for a particular interface. This language binding does not use queryInterface. Instead objects can be cast to the desired interface. For example:

 // C#
 try {
   XFoo bar = (XFoo) obj;
 } catch (System.InvalidCastException e) {
     // obj does not support XFoo
 }
 
 // using keywords is and as
 if (obj is XFoo) {
     // obj supports XFoo
 }
 
 XFoo foo = obj as XFoo;
 if (foo != null)
 {
     // obj supports XFoo
 }
 
 // C++ with managed extensions
 XFoo * pFoo = dynamic_cast< XFoo * >( obj );
 if (XFoo != 0)
 {
     // obj supports XFoo
 }  
 
 try {
 XFoo * pFoo = __try_cast< XFoo * >( obj );
 } catch (System::InvalidCastException * e) {
     // obj does not support XFoo
 }
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools