Freigeben über


Optimization of ActiveX Controls

If you use Automation or ActiveX controls in your application, you can fine-tune the application to get the best performance out of both ActiveX controls and Automation.

Using ActiveX Controls Efficiently

For best performance when using ActiveX controls in your forms, use the following suggestions:

  • Start Automation servers in advance. Controls bound to general fields will generally perform better when the servers for those data types (like Microsoft Excel or Word) are already running on the client's machine.
  • Insert objects "As Icon." When you insert an ActiveX control into a field, insert it as an icon or placeholder rather than as an entire object. This reduces the amount of storage space required because Visual FoxPro stores a presentation image with the object, which can consume a lot of storage space. Inserting an object as an icon also increases performance for drawing the object.
  • Use image controls. If you want to display a bitmap (such as a company logo), image controls are much faster than OLEBound controls.
  • Use manual links whenever possible. Manual links to objects are faster because they avoid the notification time required for automatic links, and because the server doesn't need to be started to draw the object. If you don't need to update an object frequently, use manual links.

Optimizing Automation Performance

If your application interacts with other applications, you can get the best performance using the following techniques.

Avoiding Multiple Instances of the Server

In some cases, Automation servers (such as Microsoft Excel) will always start a new instance, even if one is already running. To remedy this and improve performance, use the GetObject( ) function instead of CreateObject( ). For example, the following call will always use an existing instance, if it exists:

x = GetObject(,"excel.Application")

In contrast, the following call creates a new instance:

x = CreateObject("excel.Application")

If you call GetObject( ) but the server isn't already running, you will get error 1426. In that case, you can trap for the error and call CreateObject( ):

ON ERROR DO oleErr WITH ERROR()
x = GetObject(,"excel.application")
ON ERROR  && restore system error handler

PROCEDURE oleErr
PARAMETER mError
IF mError = 1426 then
 x = CreateObject("excel.application")
ENDIF

Referencing Objects Efficiently

Executing expressions that use objects within the Automation server can be expensive, particularly when evaluated multiple times. It is much faster to store objects' references to variables for reference.

See Also

Optimization of Programs | Optimizing Applications in Multiuser Environments | Optimizing Access to Remote Data | Optimizing Applications | Optimizing Your System