Name |
Description |
Delphi provides wizards to help you create various COM objects. The simplest COM objects are servers that expose properties and methods (and possibly events) through a default interface that clients can call. Two wizards, in particular, ease the process of creating simple COM objects:
| |
When designing the COM object, you need to decide what COM interfaces you want to implement. You can write a COM object to implement an interface that has already been defined, or you can define a new interface for your object to implement. In addition, you can have your object support more than one interface. For information about standard COM interfaces that you might want to support, see the MSDN documentation.
| |
The COM object wizard performs the following tasks:
| |
The Automation object wizard performs the following tasks:
| |
Many of the COM wizards require you to specify an instancing mode for the object. Instancing determines how many instances of your object clients can create in a single executable. If you specify a Single Instance model, for example, then once a client has instantiated your object, COM removes the application from view so that other clients must launch their own instances of the application. Because this affects the visibility of your application as a whole, the instancing mode must be consistent across all objects in your application that can be instantiated by clients. That is, you should not create... more | |
When creating an object using a wizard, you select a threading model that your object agrees to support. By adding thread support to your COM object, you can improve its performance, because multiple clients can access your application at the same time. The following table lists the different threading models you can specify. Threading models for COM objects | |
When you use a wizard to create a COM object, the wizard automatically generates a type library (unless you specify otherwise in the COM object wizard). The type library provides a way for host applications to find out what the object can do. It also lets you define your object's interface using the Type Library editor. The interfaces you define in the Type Library editor define what properties, methods, and events your object exposes to clients. Note: If you selected an existing interface in the COM object wizard, you do not need to add properties and methods. The definition... more | |
The Automation wizard automatically generates event code if you check the option, Generate Support Code in the Automation Object wizard dialog box. For a server to support traditional COM events, it must provide the definition of an outgoing interface which is implemented by a client. This outgoing interface includes all the event handlers the client must implement to respond to server events. When a client has implemented the outgoing event interface, it registers its interest in receiving event notification by querying the server's IConnectionPointContainer interface. The IConnectionPointContainer interface returns the server's IConnectionPoint interface, which the client then uses to pass... more | |
The Automation Object wizard implements a dual interface by default, which means that the Automation object supports both
Note: Any interfaces generated by the COM Object wizard that do not descend from IDispatch only support VTable calls. | |
A dual interface is a custom interface and a dispinterface at the same time. It is implemented as a COM VTable interface that derives from IDispatch. For those controllers that can access the object only at runtime, the dispinterface is available. For objects that can take advantage of compile-time binding, the more efficient VTable interface is used. Dual interfaces offer the following combined advantages of VTable interfaces and dispinterfaces:
| |
Automation controllers are clients that use the COM IDispatch interface to access the COM server objects. The controller must first create the object, then query the object's IUnknown interface for a pointer to its IDispatch interface. IDispatch keeps track of methods and properties internally by a dispatch identifier (dispID), which is a unique identification number for an interface member. Through IDispatch, a controller retrieves the object's type information for the dispatch interface and then maps interface member names to specific dispIDs. These dispIDs are available at runtime, and controllers get them by calling the IDispatch method,GetIDsOfNames. Once... more | |
Custom interfaces are user-defined interfaces that allow clients to invoke interface methods based on their order in the VTable and knowledge of the argument types. The VTable lists the addresses of all the properties and methods that are members of the object, including the member functions of the interfaces that it supports. If the object does not support IDispatch, the entries for the members of the object's custom interfaces immediately follow the members of IUnknown. If the object has a type library, you can access the custom interface through its VTable layout, which you can get using the... more | |
For out-of-process and remote servers, you must consider how COM marshals data outside the current process. You can provide marshaling:
Note: The first method (using IDispatch) is only available... more | |
You can register your server object as an in-process or an out-of-process server. For more information on the server types, see In-process. Note: Before you remove a COM object from your system, you should unregister it. | |
Once you have created a COM server application, you will want to test it before you deploy it. |
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|