RAD Studio |  |

Working with type libraries
Collapse All
Topics

Name | Description
Working with Type Libraries: Overview | Type libraries are files that include information about data types, interfaces, member functions, and object classes exposed by a COM object. They provide a way to identify the types of objects and interfaces that are available on a server. For a detailed overview on why and when to use type libraries, see Type libraries. A type library can contain any and all of the following: Information about custom data types such as aliases, enumerations, structures, and unions. Descriptions of one or more COM elements, such as an interface, dispinterface, or CoClass. Each of these descriptions is commonly referred to... more
Type Library Editor | The Type Library Editor enables developers to examine and create type information for COM objects. Using the Type Library Editor can greatly simplify the task of developing COM objects by centralizing the tasks of defining interfaces, CoClasses, and types, obtaining GUIDs for new interfaces, associating interfaces with CoClasses, updating implementation units, and so on. The Type Library Editor outputs two types of file that represent the contents of the type library: Type Library editor files
Parts of the Type Library Editor | The main elements of the Type Library Editor are described in the following table: Type Library editor parts
Toolbar | The Type Library Editor's toolbar, located at the top of the Type Library Editor, contains buttons that you click to add new objects into your type library. The first group of buttons let you add elements to the type library. When you click a toolbar button, the icon for that element appears in the object list pane. You can then customize its attributes in the right pane. Depending on the type of icon you select, different pages of information appear to the right. The following table lists the elements you can add to your type library: Icons Representing... more
Object List Pane | The Object list pane displays all the elements of the current type library in a tree view. The root of the tree represents the type library itself, and appears as the following icon: Descending from the type library node are the elements in the type library: When you select any of these elements (including the type library itself), the pages of type information to the right change to reflect only the relevant information for that element. You can use these pages to edit the definition and properties of the selected element. You can manipulate the elements in the object... more
Status Bar | When editing or saving a type library, syntax, translation errors, and warnings are listed in the Message pane. For example, if you specify a type that the Type Library Editor does not support, you will get a syntax error. For a complete list of types supported by the Type Library Editor, see Valid types.
Pages of Type Information | When you select an element in the object list pane, pages of type information appear in the Type Library Editor that are valid for the selected element. Which pages appear depends on the element selected in the object list panel, as follows:
Type Library Elements | The Type Library interface as represented in the Type Library Editor can seem overwhelmingly complicated at first. This is because it represents information about a great number of elements, each of which has its own characteristics. However, many of these characteristics are common to all elements. For example, every element (including the type library itself) has the following: Name, which is used to describe the element and which is used when referring to the element in code. GUID (globally unique identifier), which is a unique 128-bit value that COM uses to identify the element. This should always be supplied... more
Using the Type Library Editor | Using the type library editor, you can create new type libraries or edit existing ones. Typically, an application developer uses a wizard to create the objects that are exposed in the type library, letting Delphi generate the type library automatically. Then, the automatically-generated type library is opened in the Type Library editor so that the interfaces can be defined (or modified), type definitions added, and so on. However, even if you are not using a wizard to define the objects, you can use the Type Library editor to define a new type library. In this case, you must create any... more
Valid Types | In the Type Library editor, you use different type identifiers, depending on whether you are working in IDL or Delphi. Specify the language you want to use in the Environment options dialog. The following types are valid in a type library for COM development. The Automation compatible column specifies whether the type can be used by an interface that has its Automation or Dispinterface flag checked. These are the types that COM can marshal via the type library automatically.
SafeArrays | COM requires that arrays be passed via a special data type known as a SafeArray. You can create and destroy SafeArrays by calling special COM functions to do so, and all elements within a SafeArray must be valid automation-compatible types. The Delphi compiler has built-in knowledge of COM SafeArrays and automatically calls the COM API to create, copy, and destroy SafeArrays. In the Type Library Editor, a SafeArray must specify the type of its elements. For example, the following line from the text page declares a method with a parameter that is a SafeArray with an element type... more
Using Object Pascal or IDL Syntax | The Code page of the Type Library editor displays your type information in RIDL format (Restricted Interface Definition Language). The format resembles Microsoft's IDL sytnax. However, RIDL supports only a subset of IDL. Like Delphi applications in general, identifiers in type libraries are case insensitive. Identifiers can be as many as 255 characters long, and for maximum portability should begin with a letter or an underscore (_).
Creating a New Type Library | Use the Type Library Wizard to create a type library that is independent of a particular COM object. For example, you might want to define a type library that contains type definitions that you use in several other type libraries. You can then create a type library of basic definitions and add it to the uses page of other type libraries. You can also use the wizard to create a type library for an object that is not yet implemented. Once the type library contains the interface definition, you can use the COM object wizard to generate a CoClass and... more
Opening an Existing Type Library | When you use the wizards to create an Automation object, COM object, transactional object, or a remote data module, a type library is automatically created with an implementation unit. Starting with the 2009 product, the wizards create type libraries in a text-based format (RIDL files). However, you can still open type libraries in .tlb format that are associated with previous versions or other products (servers) that are available on your system. The Type Library Explorer enables you to examine .tlb files.
Adding an Interface to the Type Library |
Modifying an Interface Using the Type Library | There are several ways to modify an interface or dispinterface once it is created. You can change the interface's attributes using the page of type information that contains the information you want to change. Select the interface in the Object List pane and then use the controls on the appropriate page of type information. For example, you may want to change the parent interface using the attributes page, or use the flags page to change whether or not it is a dual interface. You can edit the interface declaration directly by selecting the interface in the object list pane and... more
Adding Properties and Methods to the Type Library |
Adding a CoClass to the Type Library | The easiest way to add a CoClass to your project is to choose FileNewOther from the main menu in the IDE and use the appropriate wizard on the ActiveX page of the New Items dialog. The advantage to this approach is that, in addition to adding the CoClass and its interface to the type library, the wizard adds an implementation unit and updates the project file to include the new implementation unit in its uses clause. If you are not using a wizard, however, you can create a CoClass by clicking the CoClass icon on the toolbar and... more
Adding an Interface to a CoClass | CoClasses are defined by the interfaces they present to clients. While you can add any number of properties and methods to the implementation class of a CoClass, clients can only see those properties and methods that are exposed by interfaces associated with the CoClass. To associate an interface with a CoClass, right-click in the Implements page for the class and choose Insert Interface to display a list of interfaces from which you can choose. The list includes interfaces that are defined in the current type library and those defined in any type libraries that the current type library references. Choose... more
Adding an Enumeration to the Type Library |
Adding an Alias to the Type Library |
Adding a Record or Union to the Type Library |
Adding a Module to the Type Library |
Saving and Registering Type Library Information | After modifying your type library, you'll want to save and register the type library information. Saving the type library automatically updates: Both the text-based type library file (.ridl extension) and the binary type library file (.tlb extension). The Project_TLB unit that represents its contents The implementation code for any CoClasses that were generated by a wizard. Note: The type library is stored as separate text (.RIDL) and binary (.TLB) files, but is also linked into the server (.EXE, DLL, or .OCX). The Type Library Editor gives you toolbar buttons for storing your type library information: Refresh updates... more
Apply Updates Dialog | The Apply Updates dialog appears when you refresh, register, or save the type library if you have selected Display updates before refreshing in the ToolsOptionsType Library page (which is not checked off by default ). Without this option, the Type Library Editor automatically updates the sources of the associated object when you make changes in the editor. With this option, you have a chance to veto the proposed changes when you attempt to refresh, save, or register the type library. The Apply Updates dialog will warn you about potential errors, and will insert TODO comments in your source... more
Saving a Type Library | For 2009, RAD Studio stores type libraries as separate text-based files (RIDL, or Restricted Interface Definition Language); The RIDL file, which represents the TLB file in the Editor, is also linked into the server (.EXE, DLL, or .OCX). When you build your project, the RIDL file is saved on disk as both a .tlb file as well as a .ridl file. There are three ways to save a type library. File>Save Command: To save the project and the type library, choose FileSave. Saving a type library saves type information to a .ridl file. Save TLB Button in Type... more
Refreshing the Type Library | To refresh the type library, choose the Refresh Implementation icon on the Type Library Editor toolbar. Refreshing the type library does the following: Updates the xxxx_TLB units that contain a Delphi or C++ representation of the Type Library. Notifies the IDE's module manager to update the implementation files that contain the implementation for the CoClasses, if the type library is associated with a CoClass that was generated by a wizard. On the ToolsOptionsEnvironment OptionsDelphi OptionsType Library or the ToolsOptionsEnvironment OptionsC++ OptionsType Library dialog box, you can designate specific instances when the... more
Registering the Type Library | To register the type library, click the Register Type Library button on the Type Library Editor toolbar. Typically, you do not need to explicitly register a type library because it is registered automatically when you register your COM server application (see Registering a COM object). However, when you create a type library using the Type Library wizard, the type library is not associated with a server object. In this case, you can register the type library directly using the toolbar. Registering the type library adds an entry to the Windows registry for the type library.
Deploying Type Libraries | By default, when you have a type library that was created as part of an Automation server project, the type library is automatically linked into the .DLL, .OCX, or EXE as a resource. You can, however, deploy your application with the type library as a separate .TLB, as Delphi maintains the type library, if you prefer. Historically, type libraries for Automation applications were stored as a separate file with the .TLB extension. Now, typical Automation applications compile the type libraries into the .OCX or .EXE file directly. The operating system expects the type library to be the first resource in... more
GenTLB.exe | A new type library generator (GenTLB.exe) has been added to RAD Studio. When you compile or build a project that contains a type library, the type library generator compiles the text-based RIDL file into the binary .tlb file. You can use GenTLB.exe in your custom builds. If you use MSBuild from the command line, then MSBuild automatically uses GenTLB.exe. Examples To create AppName.tlb from the contents of AppName.ridl:
RIDL File | A new file type has been added to the COM architecture for 2009 – the RIDL file (Restricted Interface Definition Language). The RIDL file is the storage mechanism that the project uses to persist the type library data to disk. RAD Studio now uses the .tlb file as an intermediate file (like a .res, .dcu, .obj, and so forth). This means that you can rebuild the .tlb file from the command line (outside the IDE), that .tlb files can be edited with a text editor, and the history is stored by the IDE. The Type Library Editor... more

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