RAD Studio |  |

Creating COM clients
Collapse All
Topics

Name | Description
Creating COM Clients | COM clients are applications that make use of a COM object implemented by another application or library. The most common types are applications that control an Automation server (Automation controllers) and applications that host an ActiveX control (ActiveX containers). At first glance these two types of COM client are very different: The typical Automation controller launches an external server EXE and issues commands to make that server perform tasks on its behalf. The Automation server is usually nonvisual and out-of-process. The typical ActiveX client, on the other hand, hosts a visual control, using it much the same way you use... more
Importing Type Library Information | To make information about the COM server available to your client application, you must import the information about the server that is stored in the server's type library. Your application can then use the resulting generated classes to control the server object. There are two ways to import type library information: You can use the Import Component dialog to import all available information about the server types, objects, and interfaces. This is the most general method, because it lets you import information from any type library and can optionally generate component wrappers for all creatable CoClasses in the type... more
Code Generated When You Import Type Library Information | Once you import a type library, you can view the generated TypeLibName_TLB unit. At the top, you will find the following: First, constant declarations giving symbolic names to the GUIDS of the type library and its interfaces and CoClasses. The names for these constants are generated as follows: the GUID for the type library has the form LBID_TypeLibName, where TypeLibName is the name of the type library. The GUID for an interface has the form IID_InterfaceName, where InterfaceName is the name of the interface. The GUID for a dispinterface has the form DIID_InterfaceName,... more
Controlling an Imported Object | After importing type library information, you are ready to start programming with the imported objects. How you proceed depends in part on the objects, and in part on whether you have chosen to create component wrappers. There are two basic approaches: Using component wrappers. Writing client code based on type library definitions.
Using Component Wrappers | If you generated a component wrapper for your server object, writing your COM client application is not very different from writing any other application that contains VCL components. The server object's properties, methods, and events are already encapsulated in the VCL component. You need only assign event handlers, set property values, and call methods. To use the properties, methods, and events of the server object, see the documentation for your server. The component wrapper automatically provides a dual interface where possible. Delphi determines the VTable layout from information in the type library. In addition, your new component inherits certain important... more
Writing Client Code Based On Type Library Definitions | Although you must use a component wrapper for hosting an ActiveX control, you can write an Automation controller using only the definitions from the type library that appear in the TypeLibName_TLB unit. This process is a bit more involved that letting a component do the work, especially if you need to respond to events. The following topics describe how to implement the various actions your Automation controller needs to perform: Connect to the server. Control the Automation server using a dual interface. Control the Automation server using a dispinterface. Respond to events generated by the Automation... more
Connecting to a Server | Before you can drive an Automation server from your controller application, you must obtain a reference to an interface it supports. Typically, you connect to a server through its main interface. If the main interface is a dual interface, you can use the creator objects in the TypeLibName_TLB.pas file. The creator classes have the same name as the CoClass, with the prefix "Co" added. You can connect to a server on the same machine by calling the Create method, or a server on a remote machine using the CreateRemote method. Because Create and CreateRemote are class methods, you... more
Controlling an Automation Server Using a Dual Interface | After using the automatically generated creator class to connect to the server, you call methods of the interface. For example,
Controlling an Automation Server Using a Dispatch Interface | Typically, you use the dual interface to control the Automation server. However, you may find a need to control an Automation server with a dispatch interface because no dual interface is available.
Handling Events in an Automation Controller | When you generate a Component wrapper for an object whose type library you import, you can respond to events simply using the events that are added to the generated component. If you do not use a Component wrapper, however, (or if the server uses COM+ events), you must write the event sink code yourself.
Creating Clients for Servers That Do Not Have a Type Library | Some older COM technologies, such as object linking and embedding (OLE), do not provide type information in a type library. Instead, they rely on a standard set of predefined interfaces. To write clients that host such objects, you can use the TOleContainer component. This component appears on the System category of the Tool Palette. TOleContainer acts as a host site for an Ole2 object. It implements the IOleClientSite interface and, optionally, IOleDocumentSite. Communication is handled using OLE verbs.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!