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:Documentation/Developers Guide/Professional UNO)
m
Line 6: Line 6:
 
|NextPage=Documentation/DevGuide/ProUNO/CLI/Writing Client Programs
 
|NextPage=Documentation/DevGuide/ProUNO/CLI/Writing Client Programs
 
}}
 
}}
 +
[[zh:Zh/Documentation/DevGuide/ProUNO/CLI/Lifetime Management and Obtaining Interfaces]]
 
{{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 [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.

Revision as of 03:55, 18 July 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
In other languages