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

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Robot: Changing Category:Professional UNO)
 
(5 intermediate revisions by 3 users not shown)
Line 6: Line 6:
 
|NextPage=Documentation/DevGuide/ProUNO/CLI/Writing Client Programs
 
|NextPage=Documentation/DevGuide/ProUNO/CLI/Writing Client Programs
 
}}
 
}}
 +
{{Documentation/DevGuideLanguages|Documentation/DevGuide/ProUNO/CLI/{{SUBPAGENAME}}}}
 
{{DISPLAYTITLE:Lifetime Management and Obtaining Interfaces}}
 
{{DISPLAYTITLE:Lifetime Management and Obtaining Interfaces}}
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 [http://api.openoffice.org/docs/common/ref/com/sun/star/uno/XInterface.html#acquire com.sun.star.uno.XInterface:acquire] and [http://api.openoffice.org/docs/common/ref/com/sun/star/uno/XInterface.html#release com.sun.star.uno.XInterface:release] are not needed.
+
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 <idlm>com.sun.star.uno.XInterface:acquire</idlm> and <idlm>com.sun.star.uno.XInterface:release</idlm> are not needed.
  
 
<idls>com.sun.star.uno.XInterface</idls> has a third method, <idlm>com.sun.star.uno.XInterface:queryInterface</idlm>, which is used to query an object for a particular interface. This language binding does not use <idlm>com.sun.star.uno.XInterface:queryInterface</idlm>. Instead objects can be cast to the desired interface. For example:
 
<idls>com.sun.star.uno.XInterface</idls> has a third method, <idlm>com.sun.star.uno.XInterface:queryInterface</idlm>, which is used to query an object for a particular interface. This language binding does not use <idlm>com.sun.star.uno.XInterface:queryInterface</idlm>. Instead objects can be cast to the desired interface. For example:
 
+
<syntaxhighlight lang="c">
 
   // C#
 
   // C#
 
   try {
 
   try {
Line 28: Line 29:
 
       // obj supports XFoo
 
       // obj supports XFoo
 
   }
 
   }
 
+
</syntaxhighlight>
 +
 
 +
<syntaxhighlight lang="cpp">
 
   // C++ with managed extensions
 
   // C++ with managed extensions
 
   XFoo * pFoo = dynamic_cast< XFoo * >( obj );
 
   XFoo * pFoo = dynamic_cast< XFoo * >( obj );
Line 41: Line 44:
 
       // obj does not support XFoo
 
       // obj does not support XFoo
 
   }
 
   }
 
+
</syntaxhighlight>
 
{{PDL1}}
 
{{PDL1}}
  
[[Category:Documentation/Developers Guide/Professional UNO]]
+
[[Category:Documentation/Developer's Guide/Professional UNO]]

Latest revision as of 15:56, 23 December 2020



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 acquire and 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
In other languages