Finding Objects and Properties


OOo Basic has functions to find variables and their properties based on their names . This functionality was initially described to me as poorly documented, possibly deprecated, and buggy -and I cannot disagree . Use FindObject to obtain a reference to a variable with a given name , and FindPropertyObject to obtain a reference to a named property of an object. The macro in Listing 14 demonstrates some of the idiosyncrasies of the FindObject and FindPropertyObject functions.

Listing 14: TestFindObject is found in the UNO module in this chapter's source code files as SC09.sxw.
start example
 Sub TestFindObject   Dim oTst   Dim oDoc   Dim vObj   Rem What does this really mean, found a null object and it is null   oTst = FindObject("oDoc")   If IsNull(oTst) Then Print "Found oDoc but it IsNull" 'Yes   If oTst IS oDoc Then Print "oTst and oDoc are the same" 'Yes   Rem Test against the current document   oDoc = ThisComponent   oTst = FindObject("oDoc")   REM yes   If oDoc IS ThisComponent Then Print "oDoc Is ThisComponent after assignment"   REM no   If NOT (oTst IS oDoc) Then Print "oTst is NOT oDoc after FindObject"   REM no   If NOT (oTst IS ThisComponent) Then Print "oTst is NOT ThisComponent"   REM Do it again, but do not search for oDoc   oDoc = ThisComponent   oTst = FindObject("ThisComponent")   REM yes   If oTst IS oDoc Then Print "oTst and oDoc are the same"   REM yes   If oTst IS ThisComponent Then Print "oTst and ThisComponent are the same"   REM yes   If oDoc IS ThisComponent Then Print "oDoc and ThisComponent are the same"   REM ThisComponent has a DocumentInfo property   oTst = FindPropertyObject(ThisComponent, "DocumentInfo")   Rem But it is NULL   If IsNull(oTst) Then Print "DocumentInfo object Is Null"   REM Load the Gimmicks library   GlobalScope.BasicLibraries.LoadLibrary("Gimmicks")   REM Finds the library even though it is not a variable   oDoc = FindObject("Gimmicks")   REM userfields is a module in the Gimmicks library   oTst = FindPropertyObject(oDoc, "Userfields")   REM but this works on libraries!   print (oTst Is Gimmicks.Userfields)    'True   'The StartChangesUserfields function is in the module Userfields   'Call the routine   oDoc.Userfields.StartChangesUserfields End Sub 
end example
 
Warning  

Do not use the functions FindObject and FindPropertyObject-they are poorly documented, buggy, and likely to be deprecated.

If these functions serve your purposes, use them. I tried to use these to write an object inspector, but the FindPropertyObject function did not work as I expected.




OpenOffice.org Macros Explained
OpenOffice.org Macros Explained
ISBN: 1930919514
EAN: 2147483647
Year: 2004
Pages: 203

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net