RAD Studio
ContentsIndex
PreviousUpNext
Creating COM clients
Name 
Description 
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 
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 
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 
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:  
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 
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:
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 
After using the automatically generated creator class to connect to the server, you call methods of the interface. For example,  
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. 
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. 
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. 
The Microsoft .NET Framework and the Common Language Runtime (CLR) provide a runtime environment in which components written in .NET languages can seamlessly interact with each other. A compiler for a .NET language does not emit native machine code. Instead, the language is compiled to an intermediate, platform neutral form called Microsoft Intermediate Language (MSIL, or IL for short). The modules containing IL code are linked together to form an assembly. An assembly can be made up of multiple modules, or it can be a single file. In either case, an assembly is a self-describing entity; it holds information about... more 
If you are developing new components with the .NET Framework, then you need to install the full .NET Framework SDK, which is available from Microsoft's MSDN website: msdn.microsoft.com. If you are only using .NET types directly from the .NET Framework core assemblies, then you only need to install the .NET Framework Redistributable, also available from the MSDN website. Of course, any unmanaged application that relies on services provided by the .NET Framework will require the .NET Framework Redistributable to be deployed on the end-user's machine.
.NET components are exposed to unmanaged code through the use of proxy objects called... more 
Both COM, and the .NET Framework contain mechanisms to expose type information. In COM, one such mechansim is the type library. Type libraries are a binary, programming language-neutral way for a COM object to expose type metadata at runtime. Because type libraries are opened and parsed by system APIs, languages such as Delphi can import them and gain the advantages of vtable binding, even if the component was written in a different programming language.
In the .NET development environment, the assembly doubles as a container for both IL, and type information. The .NET Framework contains classes that are used to... more 
When you examine a type library for a .NET component, you might - depending on how the component was designed and built - find only an empty class interface. The class interface will not contain any information about the parameters expected by the methods implemented by the class. Also notably absent, are the dispids for the methods of the class. The reason for this are the problems that can arise when a new version of the component is created.
In COM, inheriting via interface is the only option. In the .NET Framework, inheriting via interface or inheriting via implementation is... more 
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!