共用方式為


Server Enhancements

Visual FoxPro includes several enhancements for COM servers that provide improved interoperability with core platform technologies such as COM+ Services.

Implement Interfaces

A Visual FoxPro COM component can implement a valid COM interface, defined by another COM component. This means that your Visual FoxPro class contains all the members (properties, events, and methods) of this COM interface. It is not true-inheritance in the strict fashion that Visual FoxPro OOP supports, but rather a contract that the Visual FoxPro class definition will contain the same set of members the COM component's class contains.

To implement a COM interface, use the new IMPLEMENTS clause of the DEFINE CLASS command.

For examples of Visual FoxPro COM components using the new IMPLEMENTS support (and other new server enhancements), see the collection of COM+ samples in the ...\Samples\COM+\ directory.

Event Binding

Visual FoxPro supports the ability to bind to events from other COM components such as ADO Recordsets. (For example, you can have Fox code run when the record pointer is moved in an ADO Recordset.)

Event binding is supported using the new EventHandler( ) Function. To bind a Visual FoxPro class to events from a COM component, the Visual FoxPro class must implement the COM component's event interface.

This type of event handling is referred to as tightly-coupled, in which both event source and event sink objects are live at the time the event occurs. The EventHandler( ) function is used for events raised by the IConnectionPoint technology. Visual FoxPro does not support the ability to raise events through IConnectionPoint.

The preferred strategy for event handling between COM components is by using the COM+ events technology, which is part of COM+ Services. With COM+ events, Visual FoxPro COM components also can be used as an event source (publisher). Additionally, COM+ Events provide a loosely coupled architecture, which allows event subscribers to be inactive until events occur.

Early Binding Support

Certain COM classes do not support an IDispatch interface (late-binding). This is often the case when you received an OLE error of "No such interface supported." returned from a CreateObject() call. Visual FoxPro now makes it possible for you to work with COM components using interfaces through early-binding calls.

The CREATEOBJECTEX( ) Function now makes it possible for you to optionally specify a third parameter that lets you create an instance of a COM component using early-binding. You can use the new GETINTERFACE( ) Function to return an early-bound object reference from an existing one.

Type Library Strong Typing

Visual FoxPro provides strong typing control that makes coding easier and less error-prone for methods in a DEFINE CLASS command. With strong typing you can specify the data type for parameters and return values of methods in your COM components using the AS clause. For more information, see DEFINE CLASS. Visual FoxPro does not enforce typing at run time. Strong typing is used when writing out the class definition in a Type Library (OLEPUBLIC) or viewing parameter information with IntelliSense.

Strong typing also provides the capability of passing parameters by reference in methods.

Type Library Attribute Control

In addition to the strong typing information written out to a Type Library (OLEPUBLIC), you can specify additional Type Library attributes for properties and methods using the COMATTRIB array (for more information, see DEFINE CLASS). Similar to Access/Assign methods, you add the COMATTRIB name to the end of a property or method (for example, MyMethod_COMATTRIB). The COMATTRIB array can be used to specify extended Type Library information such as a help string, capitalization, optional parameters or whether a property is read-only.

Return Array from Methods

Visual FoxPro makes it possible for you to return arrays directly from a class method using the @ operator. This support is added primarily for Visual FoxPro COM components, which might have to communicate with other COM components such as those written in Visual Basic or Visual C++, which might expect an array returned directly from a method. This also can affect methods implemented from an interface using the IMPLEMENTS clause.

Use member arrays as in the following example:

   DEFINE CLASS t1 AS custom OLEPUBLIC
      DIMENSION Arrayelement[3]
      FUNCTION GetMyArray() AS array
         this.Arrayelement[1] = 1
         this.Arrayelement[2] = 2   
         this.Arrayelement[3] = 3
         RETURN @THIS.Arrayelement
      ENDFUNC
   ENDDEFINE

Because such arrays must be in scope after the method call, LOCAL and PRIVATE arrays are invalid in these declarations. You must use either a PUBLIC or a member array. This array support does not work with the STORE TO command.

FoxRuntime Registry Key Identifier

Visual FoxPro COM servers now register a new registry key in the system registry. The new key FoxRuntime contains a reference to the run-time library used by the server. The new registry key is written out as follows with <guid> referencing the GUID of the Visual FoxPro COM server:

Key: HKEY_CLASSES_ROOT\CLSID\<guid>\FoxRuntime
Value: VFP7T.DLL

Session Class Updates

Because of its ability to isolate data with a private data session, the Session class is a recommended base class for use in creating Visual FoxPro COM servers. With Visual FoxPro, the following updates have been made to this class:

  • Intrinsic properties, methods and events are no longer written out to the Type Library.
  • Only the custom properties and methods that you specify are written out.
  • In previous versions, you needed to manually make each member HIDDEN.
  • The following SET values have a new default setting for private data session with Session class:
    • EXCLUSIVE = OFF
    • TALK = OFF
    • SAFETY = OFF

Advanced Server Capabilities

Visual FoxPro provides an assortment of new functions for working with COM components at a very low level. These are for use by advanced developers with a strong understanding of the architecture and rules of COM. These include a number of new SYS() functions.

The new COMPROP( ) Function provides the ability to control specific behaviors of a COM component. These behaviors might differ between COM components, so a thorough understanding of the component is often necessary before setting COMPROP named properties. For more information, see SYS(2336) - Critical Section support, SYS(2339) - Call CoFreeUnusedLibraries when COM object is released, SYS(2340) - NT Service Support, SYS(3095) - IDispatch Pointer, SYS(3096) - IDispatch Object Reference, SYS(3097) - Add Reference to Object, SYS(3098) - Release Object reference.

See Also

Automation and COM Servers | COMCLASSINFO( ) Function | COMARRAY( ) Function