OOo Basic defines the variables BasicLibraries and DialogLibraries to access libraries contained in a document. The behavior is the same as their GlobalScope counterparts except that they access the library container for the current document. Modify Listing 4 by removing all references to GlobalScope, and the macro acts on the current document.
Although the BasicLibraries and DialogLibraries variables provided by OOo Basic provide an excellent method of accessing dialogs and libraries contained in a document, you may find code that uses the deprecated method getLibraryContainer(). Each document supports the method getLibraryContainer(). The returned object supports the method getModuleContainer(), which returns the contained Basic modules, and the method getDialogContainer(), which in my testing always returns a null object. Table 3 shows how to obtain a module using old and new methods .
Using BasicLibraries | Using oDoc.getLibraryContainer() |
---|---|
oLibs = BasicLibraries If oLibs. hasByName("TestLib") Then oLib = oLibs.getByName("TestLib") If oLib.hasByName("AMod") Then oMod = oLib.getByName("AMod") End If End If | oLibs = ThisComponent.getLibraryContainer() If oLibs.hasByName("TestLib") Then oLib = oLibs.getByName("TestLib") oMods = oLib.getModuleContainer() If NOT IsNull(oMods) Then If oMods.hasByName("AMod") Then oMod = oMods.getByName("AMod") End If End If End If |