Hi,
When trying to access a procedure inside a library one must issue the command:
BasicLibraries.LoadLibrary(“LibraryName”).
Till now everything ok.
But if one doesn’t need or want that library loaded, is there a command to unload the loaded library?
Sometimes it could be usefull.
I search a lot and couldn’t find anything.
Thanks in advance.
Here is a short description abot handling the Libraries:
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Basic/Accessing_Libraries_from_Basic
There are bugous links on that site, the right links:
Remove: Interface XLibraryContainer
Rename: Interface XLibraryContainer2
Hi,
When trying to access a procedure inside a library one must issue the
command:
BasicLibraries.LoadLibrary(“LibraryName”).
note: if and only if the library is not “Standard”.
→ A container “Standard” library is always loaded at startup.
Till now everything ok.
But if one doesn’t need or want that library loaded, is there a command
to unload the loaded library?
As you might have found from the links provided by Tibor, there’s no
such method as “unloadLibrary()”. Thus, unloading a library is not
possible, provided it has been loaded once.
Sometimes it could be usefull.
In which context? Loading a library is only necessary if you want to
access a subprogram stored in that very library. This means that is is
possible that you need to access that subprogram again (or another
related one) in a future step.
My take here would be:
- Whenever possible, always have your subprograms in a module which is
part of the “Standard” library bacause that one is always loaded at startup. - If not possible (or not desired. Ex: library encryption), group your
subprograms in dedicated modules in as few other libraries as possible.
This would minimize the “loadLibrary()” calls and optimize the
subprograms uses.
HTH,
@Zizi64: Did you actually research (test) the removeLibrary
method concerning the question whether it actually removes the library from its storage location or only unloads it (“removing” the access only). I never tried it, but would assume the first case (if not “read only”?).
We need to be careful, and should start with createLibraryLink()
. The stored library (probably contained in a user profile) must also be retrievable from a backup.
See also: LibreOffice: XLibraryContainer Interface Reference
I did the test. removeLibrary removes the contained modules but not the library itself.
Note that there’s a new home for DevGuide at LibreOffice wiki, which is expected to have correct links and gradually updated content.
That’s funny.
I feel sure I never will need the feature, but it was interesting, and I invested an hour (and endangered - as I found too late- the integrity of my local libraries) to find out more about libraries loadable from arbitrary locations.
Well,
Const libPath = "C:\Users\MYPERSONALPATH\Office\test\libraryAccess\xStandard"
Const libContSrvcN = "com.sun.star.script.ApplicationScriptLibraryContainer"
Global libContSrvc As Object
Sub loadTheLib()
libContSrvc = CreateUnoService(libContSrvcN)
libUrl = ConvertToURL(libPath)
libLink = libContSrvc.createLibraryLink("otherStandard", libUrl, False) REM False=Editable!
libContSrvc.loadLibrary("otherStandard")
End Sub
Sub unloadTheLib()
libContSrvc.removeLibrary("otherStandard")
End Sub
worked exactly as expected - with the exception that function names from the otherStandard
were found if newly parsed after the loadTheLib
(no #NAME or #MACRO error), but the functions weren’t actually called, and did not return results. (#VALUE!).
A simple hello-world-Sub from the loaded library was run when called via >Tools>Macros>Run
.
Any clearvoyants here?