When I studied VCL in a simple way, there were a lot of questions raised by netizens, and it seemed that they were correct. But this does not shake Li Wei's position in the Greater China Delphi industry, because he should be a master who understands the entire system, not a master who has doubts. It is incredible that he can write such a huge volume of thoughts and energy, not to mention that he has written many other books and done many other things.
I have carefully studied VCL myself. Besides studying Li Wei's masterpiece, I still have many of my experiences. I will also write it here slowly, A world-class basic programming library for Windows is so difficult and too huge that Li Wei cannot cover all aspects. But there is a point of philosophical thought that must be understood: engineers are the easiest way to solve the problem, achieve the goal, and solve the details of every problem encountered in the project, in addition, it is often necessary to have an unbiased solution, rather than an excessively private technique. Gossip:
1. The parent of tcontrol must be twincontrol.
The article "Understanding the message mechanism of VCL in BCB" mentions that the mouse message is handled by the iscontrolmousemsg method. You have to go to iscontrolmousemsg again. The source code is as follows:
function twincontrol. iscontrolmousemsg (VAR message: twmmouse): Boolean;
var
// tcontrol
Control: tcontrol;
P: tpoint;
begin
If getcapture = handle then
begin
Control: = nil;
If (capturecontrol <> nil) and (capturecontrol. parent = self) Then
Control: = capturecontrol;
end else
Control: = controlatpos (smallpointtopoint (message. pos), false); result: = false;
If Control <> nil then
begin
P. x: = message. xpos-control. left;
P. y: = message. ypos-control. top;
file: // The tcontrol perform method submits the message to wndproc for processing.
message. result: = control. perform (message. MSG, message. keys,
longint (pointtosmallpoint (p);
result: = true;
end;
For this reason, the tcontrol class in BCB and Delphi and all its derived classes have an inherent and necessary limitation. That is, the owner of all tcontrol classes and Their Derived classes must be the twincontrol class or the twincontrol derived class. The owner attribute can be found at earliest in tcomponent. A component or control is owned by its owner and is responsible for releasing its memory. This means that when the owner releases from the memory, the memory occupied by all its controls is also released. The best example of owner is form. The owner is also responsible for message distribution. When the owner receives a message, it is responsible for passing the messages that should be sent to its own controls to them. In this way, these controls can be used to process messages. Timage is an example: you can find that Borland does not allow timage to reload the wndproc method of tcontrol. Therefore, timage only has the ability to process mouse messages, and this capability comes from tcontrol.