Delphi COM Programming Technology three types Library __ programming

Source: Internet
Author: User
Tags uuid wrapper
It is often necessary to obtain information about components during the use and development of COM components. COM components are published in binary code, and the information will be difficult to obtain without the aid of specific tools. You can view the information for a COM component by accessing the type library. first, the basic knowledge of type library Introduction:

1, the definition of type library:

Type library: Describes the type information of one or more objects in a type library in binary form. The specific type information includes the CLSID of the component, the IID of the supported interface, the member function of the interface, its parameters and the return value type, and so on.

Ttypedcomobject class: The Ttypedcomobject class and its derived classes provide support for type libraries. COM is derived from ttypedcomobject, not tcomobjectfactory.create; At the beginning, Delphi called Ttypedcomobjectfactory.create, rather than tcomobjectfactory.create; (Delphi automatically create Xxxx_tlb.pas file;)

2, view the type library information

In a component program, a type library file (a TLB suffix name) is created specifically to define and implement the interfaces, properties, methods, and events that the component provides outward. Delphi specifically provides this file with a Pascal version of the file (TLB extension), and automatically maintain the consistency of these two files. The creation of a type library is compiled based on the description in the. tlb file. TLB files include attributes, Uses, Flags, and Text. The text file below gives a description of the file: the object type information is defined by the coclass keyword, and the corresponding wrapper class is established accordingly. The Library keyword describes the current repository information and can introduce additional type libraries through the IMPORTLIB keyword.

[

UUID (b8df2272-9f93-454e-9a95-60e32179c925),

Version (1.0),

helpstring ("projectdcom Library")

]

The library projectdcom//Describes the current database information,

{

Importlib ("Stdole2.tlb"); Introduce other type libraries

Importlib ("Midas.dll");

Importlib ("Stdvcl40.dll");

[

UUID (E30249CE-0CAB-4841-ADE4-83C5F26E52C7),

Version (1.0),

helpstring ("Dispatch Interface for Enterassist Object"),

Dual

Oleautomation

]

Interface Ienterassist:iappserver

{

};

[

UUID (19cee64a-4f7e-4626-ad07-fdcb6260c96f),

Version (1.0),

helpstring ("Enterassist Object")

]

CoClass Enterassist//Defines the object type information, enterassist its own defined name

{

[Default] interface ienterassist;

};

};


3. Benefits of using type libraries:

1>, the early connection (Early Binding) when the automatic control is written;

2>, you can create the appropriate wrapper class based on the description information in the type library. This wrapper class will make it easy to use the properties and methods provided by the Component object in the client program.

3>, utilities can be used to read and display information about COM servers containing type libraries, and automatic parameter scheduling between COM clients and servers;

4>, type libraries are necessary for some COM servers, such as automation servers and ActiveX controls;

Second, type library operation:

1. Add interfaces, properties, methods, and events to the type library

1>, the first method: Open the implementation file, select the "Edit" menu "Add to Interface" command (note: Only open the implementation file, this command to use), Delphi will pop up the increase interface dialog box. The interface item in the dialog box selects Properties/methods-istringgridx, and then writes the declaration of the T attribute in declaration (if you select the syntax Helper option in the dialog box, Delphi will always prompt you should enter the content), after clicking OK, this attribute information will be automatically added to the control's implementation file, type library file and the corresponding Pascal file. Because the interface of the control is bidirectional, read and write two methods are used in Pascal files to implement the properties of the control.
2>, second method: Use the toolbar in the type library file: You can add interfaces, methods, and properties to a COM server;
Note: The toolbar can be opened by clicking the right mouse button pop-up menu to select the text Labels command to open the title of the tool bar;

 

2, the type library file in the toolbar:
1>, Interface (interface): Automatically generate a GUID for each new interface;
2>, dispinterface (Dispatch interface): Similar to interfaces, but using different dispatching mechanisms to invoke methods in the server;
3>, CoClass (): A definition of a category that is assigned to a COM object that implements the interface; You must first use a method to create a real class object (variable) from the category definition, and then take the required interface from the class object. , and then call the desired method or property to be accessed from the acquired interface;
4>, Enumeration (enum): similar to enum type; With integer ID to indicate, rather than through collection type;
5>, Constant (constant): Only used under enumeration, can edit the name, Value property;
6>, alias (alias): Used to define a type in which a user is to include a record type or a union type (union);
7>, record (recording type): Record structure;
8>, Union (Union type): equivalent to Pascal variant type;
9>, Module (module): Modules are methods and constants of the set;
10>, Methods (method): Input parameters (in), output parameters (out), variable parameters (VAR);
11>, Property (attributes): Read only, write only, read and write three kinds;
12>, Refresh (update): Make Delphi update source file;
13>, register (registration): Compile the COM server and register the server in Windows;
14>, export (output to IDL): useful in MIDL or CORBA format;

3. Object list and page control in type library file:

Object list: Display the interface defined in the server, methods, and so on, click will show the corresponding situation, and then you can add the following things;
Page control: Displays type information for the currently selected contact in the object list. including attributes, Uses, Flags, Text;
A type library is also a resource;
You do not have to read the type library directly in the client application;



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.