RAD Studio
ContentsIndex
PreviousUpNext
COM basics
Name 
Description 
Delphi provides wizards and classes to make it easy to implement applications based on the Component Object Model (COM) from Microsoft. With these wizards, you can create COM-based classes and components to use within applications or you can create fully functional COM clients or servers that implement COM objects, Automation servers (including Active Server Objects), ActiveX controls, or ActiveForms.
COM is a language-independent software component model that enables interaction between software components and applications running on a Windows platform. The key aspect of COM is that it enables communication between components, between applications, and between clients and servers through clearly... more 
When implementing a COM application, you supply the following:  
COM clients communicate with objects through COM interfaces. Interfaces are groups of logically or semantically related routines which provide communication between a provider of a service (server object) and its clients. The standard way to depict a COM interface is as follows:
A COM Interface
For example, every COM object must implement the basic interface, IUnknown. Through a routine called QueryInterface in IUnknown, clients can request other interfaces implemented by the server.
Objects can have multiple interfaces, where each interface implements a feature. An interface provides a way to convey to the client what service it provides, without... more 
All COM objects must support the fundamental interface, called IUnknown, a typedefto the base interface type IInterface. IUnknown contains the following routines:  
An interface pointer is a pointer to an object instance that points, in turn, to the implementation of each method in the interface. The implementation is accessed through an array of pointers to these methods, which is called a vtable. Vtables are similar to the mechanism used to support virtual functions in Delphi. Because of this similarity, the compiler can resolve calls to methods on the interface the same way it resolves calls to methods on Delphi classes.
The vtable is shared among all instances of an object class, so for each object instance, the object code allocates a... more 
A COM server is an application or a library that provides services to a client application or library. A COM server consists of one or more COM objects, where a COM object is a set of properties and methods.
Clients do not know how a COM object performs its service; the object's implementation remains encapsulated. An object makes its services available through its interfaces.
In addition, clients do not need to know where a COM object resides. COM provides transparent access regardless of the object's location.
When a client requests a service from a COM object, the client passes... more 
A COM object is an instance of a CoClass, which is a class that implements one or more COM interfaces. The COM object provides the services as defined by its interfaces.
CoClasses are instantiated by a special type of object called a class factory. Whenever an object's services are requested by a client, a class factory creates an object instance for that particular client. Typically, if another client requests the object's services, the class factory creates another object instance to service the second client. (Clients can also bind to running COM objects that register themselves to support it.)... more 
With COM, a client does not need to know where an object resides, it simply makes a call to an object's interface. COM performs the necessary steps to make the call. These steps differ depending on whether the object resides in the same process as the client, in a different process on the client machine, or in a different machine across the network. The different types of servers are known as:  
Marshaling is the mechanism that allows a client to make interface function calls to remote objects in another process or on a different machine. Marshaling
  • Takes an interface pointer in the server's process and makes a proxy pointer available to code in the client process.
  • Transfers the arguments of an interface call as passed from the client and places the arguments into the remote object's process space.
For any interface call, the client pushes arguments onto a stack and makes a function call through the interface pointer. If the call to the object is not in-process, the call gets passed... more 
Sometimes, a server object makes use of another COM object to perform some of its functions. For example, an inventory management object might make use of a separate invoicing object to handle customer invoices. If the inventory management object wants to present the invoice interface to clients, however, there is a problem: Although a client that has the inventory interface can call QueryInterface to obtain the invoice interface, when the invoice object was created it did not know about the inventory management object and can't return an inventory interface in response to a call to QueryInterface. A client that... more 
Clients can always query the interfaces of a COM object to determine what it is capable of providing. All COM objects allow clients to request known interfaces. In addition, if the server supports the IDispatch interface, clients can query the server for information about what methods the interface supports. Server objects have no expectations about the client using its objects. Similarly, clients don't need to know how (or even where) an object provides the services; they simply rely on server objects to provide the services they advertise through their interfaces.
There are two types of COM clients, controllers and containers.... more 
COM was originally designed to provide core communication functionality and to enable the broadening of this functionality through extensions. COM itself has extended its core functionality by defining specialized sets of interfaces for specific purposes.
The following lists some of the services COM extensions currently provide.  
Automation refers to the ability of an application to control the objects in another application programmatically, like a macro that can manipulate more than one application at the same time. The server object being manipulated is called the Automation object, and the client of the Automation object is referred to as an Automation controller.
Automation can be used on in-process, local, and remote servers.
Automation is characterized by two key points:
  • The Automation object defines a set of properties and commands, and describes their capabilities through type descriptions. In order to do this, it must have a way to provide... more 
The Active Server Page (ASP) technology lets you write simple scripts, called Active Server Pages, that can be launched by clients via a Web server. Unlike ActiveX controls, which run on the client, Active Server Pages run on the server, and return a resulting HTML page to clients.
Active Server Pages are written in Jscript or VB script. The script runs every time the server loads the Web page. That script can then launch an embedded Automation server (or Enterprise Java Bean). For example, you can write an Automation server, such as one to create a bitmap or connect to... more 
ActiveX is a technology that allows COM components, especially controls, to be more compact and efficient. This is especially necessary for controls that are intended for Intranet applications that need to be downloaded by a client before they are used.
ActiveX controls are visual controls that run only as in-process servers, and can be plugged into an ActiveX control container application. They are not complete applications in themselves, but can be thought of as prefabricated OLE controls that are reusable in various applications. ActiveX controls have a visible user interface, and rely on predefined interfaces to negotiate I/O and display... more 
Active Documents (previously referred to as OLE documents) are a set of COM services that support linking and embedding, drag-and-drop, and visual editing. Active Documents can seamlessly incorporate data or objects of different formats, such as sound clips, spreadsheets, text, and bitmaps.
Unlike ActiveX controls, Active Documents are not limited to in-process servers; they can be used in cross-process applications.
Unlike Automation objects, which are almost never visual, Active Document objects can be visually active in another application. Thus, Active Document objects are associated with two types of data: presentation data, used for visually displaying the object on a display... more 
Type libraries provide a way to get more type information about an object than can be determined from an object's interface. The type information contained in type libraries provides needed information about objects and their interfaces, such as what interfaces exist on what objects (given the CLSID), what member functions exist on each interface, and what arguments those functions require.
You can obtain type information either by querying a running instance of an object or by loading and reading type libraries. With this information, you can implement a client which uses a desired object, knowing specifically what member functions you... more 
Delphi makes it easier to write COM server applications by providing wizards that handle many of the details involved. Delphi provides separate wizards to create the following:
  • A simple COM object
  • An Automation object
  • A COM+ Event Object
  • A Type library
  • An ActiveX library
The wizards handle many of the tasks involved in creating each type of COM object. They provide the required COM interfaces for each type of object. With a simple COM object, the wizard implements the one required COM interface, IUnknown, which provides an interface pointer to the object.
Simple COM object interface
The COM object... more 
Delphi's wizards generate classes that are derived from the Delphi ActiveX framework (DAX). Despite its name, the Delphi ActiveX framework supports all types of COM objects, not just ActiveX controls. The classes in this framework provide the underlying implementation of the standard COM interfaces for the objects you create using a wizard. The following figure illustrates the objects in the Delphi ActiveX framework:
Delphi ActiveX framework
Each wizard generates an implementation unit that implements your COM server object. The COM server object (the implementation object) descends from one of the classes in DAX:
DAX Base classes for generated implementation classes... more 
The COM+ Events system introduces a middle layer of software that decouples applications that generate events (called publishers) from applications that respond to events (called subscribers). Instead of being tightly bound to each other, publishers and subscribers can be developed, deployed and activated independently of each other.
In the COM+ Events model, an event interface is first created using the COM+ Event Object wizard. The event interface has no implementation; it simply defines the event methods that publishers will generate, and that subscribers will respond to. The COM+ event object is then installed into a COM+ Application, in the COM+... more 
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!