RAD Studio
|
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 need, and what to pass those member functions.
Clients of Automation servers, ActiveX controls, and transactional objects expect type information to be available. All of Delphi's wizards generate a type library automatically, although the COM object wizard makes this optional. You can view or edit this type information by using the Type Library Editor.
Type libraries contain type information, which indicates which interfaces exist in which COM objects, and the types and numbers of arguments to the interface methods. These descriptions include the unique identifiers for the CoClasses (CLSIDs) and the interfaces (IIDs), so that they can be properly accessed, as well as the dispatch identifiers (dispIDs) for Automation interface methods and properties.
Type libraries can also contain the following information:
With traditional development tools, you create type libraries by writing scripts in the Interface Definition Language (IDL) or the Object Description Language (ODL), then running that script through a compiler. However, Delphi automatically generates a type library when you create a COM object (including ActiveX controls, Automation objects, remote data modules, and so on) using any of the wizards on the ActiveX page of the new items dialog. (You can opt not to create a type library when using the COM object wizard.) You can also create a type library by choosing from the main menu, FileNew
Other, select the ActiveX folder under Delphi Projects, and in the right pane choose Type Library .
You can view the type library using Delphi's Type Library Editor. You can easily edit your type library using the Type Library editor and Delphi automatically updates the corresponding .tlb file (binary type library file) when the type library is saved. For any changes to Interfaces and CoClasses that were created using a wizard, the Type Library editor also updates your implementation files.
It is important to create a type library for each set of objects that is exposed to external users, for example,
The binary type library is normally a part of a resource file (.res) or a stand-alone file with a .tlb file-name extension. When included in a resource file, the type library can be bound into a server (.dll, .ocx, or .exe).
Once a type library has been created, object browsers, compilers, and similar tools can access type libraries through special type interfaces:
Special Type Interfaces
Interface |
Description |
ITypeLib |
Provides methods for accessing a library of type descriptions. |
ITypeLib2 |
Augments ITypeLib to include support for documentation strings, custom data, and statistics about the type library. |
ITypeInfo |
Provides descriptions of individual objects contained in a type library. For example, a browser uses this interface to extract information about objects from the type library. |
ITypeInfo2 |
Augments ITypeInfo to access additional type library information, including methods for accessing custom data elements. |
ITypeComp |
Provides a fast way to access information that compilers need when binding to an interface. |
Delphi can import and use type libraries from other applications by choosing Project|Import Type Library. Most of the VCL classes used for COM applications support the essential interfaces that are used to store and retrieve type information from type libraries and from running instances of an object. The VCL class TTypedComObject supports interfaces that provide type information, and is used as a foundation for the ActiveX object framework.
Even if your application does not require a type library, you can consider the following benefits of using one:
The tools for working with type libraries are listed below.
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|