Difference between revisions of "Documentation/DevGuide/ProUNO/Basic/Instantiating UNO Services"
m (typo + wikify) |
OOoWikiBot (Talk | contribs) m (FINAL VERSION FOR L10N) |
||
Line 7: | Line 7: | ||
|NextPage=Documentation/DevGuide/ProUNO/Basic/Getting Information about UNO Objects | |NextPage=Documentation/DevGuide/ProUNO/Basic/Getting Information about UNO Objects | ||
}} | }} | ||
− | + | {{Documentation/DevGuideLanguages|Documentation/DevGuide/ProUNO/Basic/{{SUBPAGENAME}}}} | |
{{DISPLAYTITLE:Instantiating UNO Services}} | {{DISPLAYTITLE:Instantiating UNO Services}} | ||
<!--<idltopic>com.sun.star.lang.ServiceManager</idltopic>--> | <!--<idltopic>com.sun.star.lang.ServiceManager</idltopic>--> |
Revision as of 08:16, 13 May 2009
In Basic, instantiate services using the Basic Runtime Library (RTL) function createUnoService()
. This function expects a fully qualified service name and returns an object supporting this service, if it is available:
oSimpleFileAccess = CreateUnoService( "com.sun.star.ucb.SimpleFileAccess" )
This call instantiates the com.sun.star.ucb.SimpleFileAccess service. To ensure that the function was successful, the returned object can be checked with the IsNull
function:
oSimpleFileAccess = CreateUnoService( "com.sun.star.ucb.SimpleFileAccess" ) bError = IsNull( oSimpleFileAccess )' bError is set to False oNoService = CreateUnoService( "com.sun.star.nowhere.ThisServiceDoesNotExist" ) bError = IsNull( oNoService )' bError is set to True
Instead of using CreateUnoService()
to instantiate a service, it is also possible to get the global UNO com.sun.star.lang.ServiceManager of the OpenOffice.org process by calling GetProcessServiceManager()
. Once obtained, use createInstance()
directly:
oServiceMgr = GetProcessServiceManager() oSimpleFileAccess = oServiceMgr.createInstance( "com.sun.star.ucb.SimpleFileAccess" ) ' is the same as oSimpleFileAccess = CreateUnoService( "com.sun.star.ucb.SimpleFileAccess" )
The advantage of GetProcessServiceManager()
is that additional information and pass in arguments is received when services are instantiated using the service manager. For instance, to initialize a service with arguments, the createInstanceWithArguments()
method of com.sun.star.lang.XMultiServiceFactory has to be used at the service manager, because there is no appropriate Basic RTL function to do that. Example:
Dim args(1) args(0) = "Important information" args(1) = "Even more important information" oService = oServiceMgr.createInstanceWithArguments _ ( "com.sun.star.nowhere.ServiceThatNeedsInitialization", args() )
The object returned by GetProcessServiceManager()
is a normal Basic UNO object supporting com.sun.star.lang.ServiceManager. Its properties and methods are accessed as described above.
In addition, the Basic RTL provides special properties as API entry points. They are described in more detail in Features of OpenOffice.org Basic:
OpenOffice.org Basic RTL Property | Description |
---|---|
ThisComponent | Only exists in Basic code which is embedded in a Writer, Calc, Draw or Impress document. It contains the document model the Basic code is embedded in. |
StarDesktop | The com.sun.star.frame.Desktop singleton of the office application. It loads document components and handles the document windows. For instance, the document in the top window can be retrieved using oDoc = StarDesktop.CurrentComponent .
|
Content on this page is licensed under the Public Documentation License (PDL). |