Delphi Interface (1)

Source: Internet
Author: User

Before, a friend praised me: Bowen easy to understand, can simplify the complex problem;

I hope that the understanding of the interface can also be helpful to everyone; But there is a lot of personal understanding, and the mistakes are pointed out.

The concept of "interface" and "class", especially "abstract class" approximation, the beginning of Delphi and no Interface, later (Delphi 3) in order to support the introduction of COM interface, and then developed into the Delphi important language characteristics.

Should be a simple understanding of the dot com, when it comes to COM, can let me think of "Flowers do not live, accidentally inserted Willow Willow Shady" of the saying.

When Microsoft developed OLE, there was a need: to use objects in other programs, which led to the birth and development of COM, while OLE slowly disappeared.

From COM to COM +, it seems that Microsoft has not made much effort (perhaps to put energy into net, but net did not leave COM), it still has a very wide range of applications, which should benefit from its advanced thinking.

Slowly way:

1, a binary 1 or 0, which can be recognized in any language;

2, a character, but also any language can be recognized;

3, a reshaping variable, but also any language can be recognized;

4, a structural body, but also any language can be recognized;

5, a function is also no problem, such as Delphi call API;

6, but a "object" or "class"? This is not easy to identify across programs and languages.

COM solves this problem! and apply to the network.

COM sets a binary standard that focuses on "object method declarations" (i.e. interfaces) and separates declarations (interfaces) from implementations.

Different languages can be used to implement this interface, and different languages (in the case of standards) can also recognize this interface, and thus implement the interaction of Cross-language objects.

Now look at this process is actually natural, quite naturally; But it seems that Microsoft's COM road is not smooth.

Microsoft through the way of COM components to provide a lot of functions, they are likely to be implemented in C + +, we use Delphi can be very good use, essentially that is Delphi followed the binary standard; Instead, Delphi's COM components, which are declared by this standard and implemented in their own language, can also be used by other languages.

What's in a COM component?

The main is a stack of interfaces (that is, declarations) and interface implementation, each interface corresponding to a counter, another contains a "class factory" thing.

This may be the case with COM steps:

1, the program at the beginning of the use of components, first contact the "interface"; This should be a query from the registry.

2, find, if this interface has not been implemented, immediately call "class factory" set up the object, and at the same time to the interface counter plus 1.

3, may be more than one program in the use of the same interface, but each with the use of "counter +1", every time the "counter-1".

4. When the usage count of the interface is 0 o'clock, the system automatically releases the objects (garbage collection mechanism) established for the interface.

Our Delphi interface is certainly the case, the use will automatically release, without manual free.

The interface continues to support COM and continues to be perfected in Delphi, and the next thing to discuss is the "interface" concept and use as a language feature.

I have been "interface" in the Mist, some books also make people more and more confused; Understand that later found in fact quite simple, compared to the "class" rule is much simpler.

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.