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

From Apache OpenOffice Wiki
Jump to: navigation, search
Line 8: Line 8:
 
{{Documentation/DevGuideLanguages|Documentation/DevGuide/ProUNO/CLI/{{SUBPAGENAME}}}}
 
{{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.
  
<idl>com.sun.star.uno.XInterface</idl> has a third method, [http://api.openoffice.org/docs/common/ref/com/sun/star/uno/XInterface.html#queryInterface com.sun.star.uno.XInterface:queryInterface], which is used to query an object for a particular interface. This language binding does not use [http://api.openoffice.org/docs/common/ref/com/sun/star/uno/XInterface.html#queryInterface com.sun.star.uno.XInterface:queryInterface]. 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:
  
 
   // C#
 
   // C#

Revision as of 14:46, 17 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