- Lifespan of an automation object
- Allocating an automation object
- Passing parameters to a method
- Using an OLE Automation object from a service
- Automation objects and WEBDEV
In french: Automation
keyword is used to declare an automation object. This object is allocated during the declaration. The Automation objects are used to handle software such as Office 2007 (Word, Excel, ...).
Using the Automation type in a site may cause problems. In Intranet, the automation objects can be used with great care in specific cases: the automation objects are a dangerous conception and they are not recommended.
// Declare an automation object
MyAutomationObject is Automation object MyServer
// Call to a method of an automation object
Declaring an automation object Hide the details
<Automation object name> is automation object <Name of automation server>
<Automation object name>: Character string
Name of the automation object to declare.
<Name of automation server>: Character string
Name of the server for the automation object.
Calling a method of an automation object Hide the details
<Name of automation object>>><Method name>([<Parameters>])
<Automation object name>: Character string
Name of the automation object to use. This object was declared beforehand.
<Method name>: Character string
Name of the method of the automation object to run. This method is given by the server.
Remark: The list of available methods depends on the server. See the documentation about the server for more details.
<Parameters>: Any type (optional)
Parameters passed to the method. To use the default value of an optional parameter, you have the ability to use "*" or the OLEIgnore constant.
Lifespan of an automation object
The automation object is created during its declaration.
The automation object is automatically destroyed at the end of the process containing its declaration.
An automation object declared "global" in the code:
- that initializes a window (or page) will be destroyed at the end of the process that closes the window (or the page).
- of project initialization will be destroyed at the end of the closing process of the first window/page of the project.
Allocating an automation object
- When allocating an automation object, the automation server is automatically started.
- To allocate an automation object with an existing instance of an automation server, use GetActiveObject.
Passing parameters to a method
- The methods of automation servers can accept one or more parameters.
- When calling a method, the sequence of parameters must be respected (see the documentation about the server for more details).
- With some automation servers, some method parameters are not valued: only the presence of the parameter is important. The value taken by this parameter has no importance.
For example, the "EditReplace" method of Word Basic accepts 10 parameters, the last one (ReplaceAll) being not valued.
In WLanguage, any ordinary value can be passed to non-valued parameters.
- The methods of some automation servers can accept optional parameters located anywhere in the list of parameters.
In WLanguage, the optional parameters must necessarily be found after the mandatory parameters.
To give any ordinary value to an optional parameter, assign the * character to the optional parameter. On the contrary, this character will not be required for the optional parameters found after the last mandatory parameter.
Using an OLE Automation object from a service
Some of the OLE Automation objects cannot be used by default from a service
For example, the allocation of an OpenOffice object from a service run with the local system account may trigger an error such as "The automation object com.sun.star.ServiceManager is not installed on your system".
m_oApplication = new Automation object "com.sun.star.ServiceManager"
In this case, the Windows configuration must be adapted to allow the OLE Automation object to be used from a service. The following operations must be performed:
- Display the control panel of Windows,
- Select "Management tools",
- Select "Component service",
- Expand the following tree structure: Computers/Workstation/DCOM configuration
- Select "OpenOffice service manager" and display its properties ("Properties" in the context menu)
- In the "Identity" tab, select a relevant identity (the user account that will run the application).
Automation objects and WEBDEV
Using the Automation type in a site may cause problems. In Intranet, the automation objects can be used with great care in specific cases. In Intranet, using the automation objects is a dangerous conception and they are not recommended.
The following problems may occur:
- Large memory consumption.
- Limit regarding the number of users.
- Workload of the automation objects used not controlled properly.
- Concurrent access to the resources and especially to the files.
- Potential locking windows of the automation object that open on the server.
We recommend that you find another solution if possible. For example:
- Using a Back Office: Save the elements to run in a file (HyperFileSQL, text, ...) and run it via a WINDEV application that operates in background task on the server.
- Using Web services, ...
Remark: In most cases, the use of automation objects requires a specific server configuration (for security reasons). See the provider for more details.
This page is also available for…