Use the EqualUnoObjects function to determine if two UNO objects are the same object. UNO structures are copied by value but UNO services are copied by reference. This means that EqualUnoObjects should always return False for two variables that contain a structure, and it might return True for UNO services.
Dim vObj vObj = ThisComponent Print EqualUnoObjects(vObj, ThisComponent) 'True Dim aProp As New com.sun.star.beans.PropertyValue vObj = aProp Print EqualUnoObjects(vObj, aProp) 'False
It is almost always safe to use Object variables to hold UNO services. It is so safe, apparently, that even the macro recorder uses Object variables to hold UNO services. Unfortunately, it is not always safe. The OOo Developer's Guide specifically states that Variant variables should be used instead of Object variables. Always use the type Variant to declare variables for UNO services, not the type Object. The OOo Basic type Object is tailored for pure OOo Basic objects-in other words, objects that can be created with the Dim As New syntax. The Variant variables are best for UNO services to avoid problems that can result from the OOo Basic specific behavior of the type Object. I asked Andreas Bregas (one of the primary developers for Sun on the OOo Basic infrastructure) about this, and he said that in most cases, both work. The OOo Developer's Guide prefers Variant because there are some odd situations in which the usage of type Object leads to an error due to the old Basic Object type semantics. But if a Basic program uses type Object, it will almost always run correctly and there should be no problems.