Open The Door

If you love him, let him learn VCL, because that’s heaven.
If you hate him, let him learn VCL, because that’s hell.
“Fantasy Night VCL”

Legend has it that a long, long time ago, there was an island between China and India. The king there married a woman every day, killed after the night, and made a fuss, and finally the daughter of the prime minister voluntarily married into the palace. On the first night, she told a very interesting story, and the king listened to it and did not kill her the next day. After that, she told a strange story every night, until the thousandth and first night, when the king finally repented. This is the famous “One Thousand and One Nights”, that is, “Heavenly Nights”. India and China land border, then it is believed that the island referred to in the legend must be somewhere in the South China Sea – the Strait of Malacca – the Indian Ocean. Now I am also on an island in between, and it is night, so I borrow the name of “Heavenly Nights”.

My favorite programming environment in junior high school was Turbo C 2.0, and I started using Visual Basic in high school. Later, it didn’t take long to find that if you want to make a slightly more complex thing, you need to constantly check the information to call the API, and you have to make a scary-looking API function declaration at the front. So I started nostalgic for the simple C language. A guy who liked Delphi knew that I hated Pascal and led me to C++ Builder. Even if I still don’t understand the simple concepts of inheritance and polymorphism in C++, I actually began to use VCL to write some inexplicable small programs (VCL is really easy to get started), began to familiarize myself with the structure of VCL, and also understood MFC and SDK, and tutored the basics of C++. Later, I felt that VCL is easy to learn and use is a lie. In fact, VCL is quite difficult to learn, even more troublesome than MFC.

I don’t know why, C++ Builder has surprisingly little material, and perhaps that’s why the C++ Builder forum is particularly human. Whether it’s the Tianji forum where I often ask inexplicable idiotic questions when I first learn VCL, or the CSDN where I often stop now, the C++ Builder forum always feels warm. Every time C++ Builder came out later than the same version of Delphi, every time I used C++, I had to look at Object Pascal’s face, which I think is what many people feel. CLX is already in Delphi 6, and the release of C++ Builder6 seems far away. Will CLX replace VCL? It seems that it will not, and it will be mentioned later. I’ve also seen a lot of posts calling for VCL to be rewritten in C++, often with little thunder and rain. Look at other people’s foreigners, just do it, and a FreeCLX project is launched.

People who use MFC are luckier than VCLs, they have Microsoft support, such as Inside Visual C++, Programming Windows 95 with MFC, MFC Internals and other Uranus superstars English masterpieces and Chinese translations, as well as excellent Chinese original works such as Mr. Hou Jie’s “Dissecting MFC”. People who use Delphi are far better than using C++ Builder, and there are far more wonderful information about Delphi than C++ Builder, very helpless, really helpless.

The editor-in-chief of C++ View magazine asked me to write a paper, and I was embarrassed because time and technology were a problem. To borrow a phrase from Mr. Hou Jie, it is very difficult to refuse the request of people who live in the same brain and shell as you day and night. So I decided to write a series of articles analyzing the internals of VCL. Of course, the so-called “fantasy” will not be of immediate help to beginners, and it will even make you feel “bored”. These articles are aimed at friends who are familiar with VCLs and have a certain C++ foundation (of course, Object Pascal and assembly are better), such as friends who want to know the underlying operation mechanism of VCL, and friends who want to develop their own application frameworks or want to rewrite VCL in C++. At the same time, I hope that you will exchange your experience in anatomy application frameworks, so that we are not limited to VCL or MFC, we can look at problems from a higher perspective and improve our abilities together.

Before diving into VCL, we must first talk about the main properties of VCL.

  • Like the frameworks included with SmallTalk and Java, VCL is part of Object Pascal, meaning there is no clear boundary between language and framework. For example, Java comes with a JDK, and any class written is a subclass of java.lang.Object. VCL and Object Pascal are the same thing. Of course, Object Pascal still allows a class to have no parent class in order to be compatible with previous Pascals, but this is no longer considered in this series.
  • Like most frameworks, VCL takes a single-root structure. That is, the structure of VCL is an inheritance tree rooted in TObject, and all VCL classes except TObject are direct or indirect subclasses of TObject.
  • Due to the linguistic nature of Object Pascal, only single inheritance is used throughout the structure.

Therefore, the essence of VCL is an Object Pascal class library, which provides two interfaces: Object Pascal and C++. Keep this in mind during the profiling process.

The structure of the article is to talk about things one at a time. Since VCL is not a separate framework like MFC, it is very tightly integrated with Object Pascal, IDE, and compiler, so it is inevitable to mention assembly in the analysis process. Of course, friends who can’t assemble don’t have to be afraid, I will explain the assembly code clearly, and try to rewrite it in C++.

Related Articles

Welcome to Boost!

The Boost web site provides free peer-reviewed portable C++ source libraries. The emphasis is on libraries which work well with the C++ Standard Library. The libraries are intended to be widely useful, and are in regular use by thousands of programmers across a broad spectrum of applications. A further goal

Read More »