Condividi tramite


Early (vtable) and Late (IDispatch) Binding

Visual FoxPro COM servers support both early (vtable) binding and the existing late binding (IDispatch) interface (together known as dual-interface support). Binding describes how clients access properties and methods of a server. Early binding provides performance benefits for Automation controllers that support early binding such as Visual Basic and the Microsoft Transaction Server. While Visual FoxPro servers support both interfaces, the one used is determined by the client.

Early Binding

If your client can detect at compile time what object a property or method belongs to, it can resolve the reference to the object at compile time. The compiled executable contains only the code to invoke the object's properties, methods, and events. This is called early binding.

Example: Visual Basic client

Dim xlApp1 As Excel.Application
Set xlApp1 = New Excel.Application

Early binding dramatically reduces the time required to set or retrieve a property value, because the call overhead can be a significant part of the total time. For method calls, the improvement depends on the amount of work the method performs. Short methods, where the call overhead is comparable to the time required to complete the task, benefit the most.

Late Binding

Although late binding is the slowest way to invoke the properties and methods of an object, there are times when it is necessary. For example, in Visual Basic you can write a function that uses an object variable to act on any of several different classes of objects. Because you don't know in advance what class of object will be assigned to the variable, you must declare it as a late-bound variable using the Visual Basic DIM As Object command.

Example: Visual Basic client

Dim xlApp2 As Object
Set xlApp2 = CreateObject("Excel.Application")

Method calls to objects created this way may run slower than calls to early-bound object methods because the client must include code in the compiled executable that will determine at run time whether or not the server has a particular method.

See Also

Compiling Source Code | Scalability and Multithreading | Interoperability and the Internet | Visual FoxPro Run-Time Libraries