WndProc method of heavy Tcontrol
Let's talk about VCL's inheritance strategy first. The top part of the inheritance chain in VCL is the TObject base class. All the VCL components and objects are inherited from TObject.
Open BCB to help view Tcontrol inheritance relationships:
Tobject->tpersistent->tcomponent->tcontrol
Oh, originally Tcontrol from Tpersistent class subclass Tcomponent class inherits from. Tpersistent Abstract base classes have the ability to use stream streams to access the properties of a class.
The Tcomponent class is the parent class for all VCL components.
That's why all the VCL components, including your custom component, can use the DFM file to access attributes "of course, if the Tpersistent subclass, I think you rarely need to derive your custom component directly from the TObject class."
The Tcontrol class is as important as its parents. In a BCB inheritance relationship, the Tcontrol class is the parent class for all VCL visual components. is actually the meaning of the control. Visualization is a control that you can see and manipulate during run time. Some of the basic properties and methods of this type of control are defined in the Tcontrol class.
The implementation of Tcontrol can be found in \borland\cbuilder5\source\vcl\control.pas. "There may be friends asking how do you know where?" Search-> found in files available with BCB is easy to find. Or use the grep feature of a Third-party plug-in. 』
OK, go into VCL's source code. It is unavoidable to complain about Borland. Hey, why use Pascal to achieve all this ...:-(
The dispatch () method that Tcontrol inherits but does not override TObject. Instead, a new method is provided by the Xycleo mentioned WndProc (). Let's take a look at what Borland engineers are writing.
Procedure Tcontrol.wndproc (var message:tmessage);
Var
Form:tcustomform;
Begin
To handle a message from the design period by a form with control
if (csdesigning in componentstate) then
Begin
Form: = Getparentform (Self);
if (Form <> nil) and (Form.designer <> nil) and
FORM.DESIGNER.ISDESIGNMSG (Self, message) then Exit;
End
If necessary, keyboard messages are handled by a form that has control
else if (message.msg >= wm_keyfirst) and (message.msg <= wm_keylast) Then
Begin
Form: = Getparentform (Self);
if (Form <> nil) and Form.wantchildkey (Self, message) then Exit;
End
Handling Mouse Messages
else if (message.msg >= wm_mousefirst) and (message.msg <= wm_mouselast) Then
Begin
If not (Csdoubleclicks in ControlStyle) then
Case Message.msg of
WM_LBUTTONDBLCLK, WM_RBUTTONDBLCLK, WM_MBUTTONDBLCLK:
Dec (message.msg, Wm_lbuttondblclk-wm_lbuttondown);
End
Case Message.msg of
WM_MOUSEMOVE:Application.HintMouseMessage (Self, message);
Wm_lbuttondown, WM_LBUTTONDBLCLK:
Begin
If Fdragmode = Dmautomatic Then
Begin
Beginautodrag;
Exit;
End
Include (Fcontrolstate, Cslbuttondown);
End
Wm_lbuttonup:
Exclude (Fcontrolstate, Cslbuttondown);
End
End
The following line is a bit special. If you are careful, you will see this message is cm_visiblechanged.
Rather than the standard Windows messages that we are familiar with at the beginning of wm_.
Although Borland did not mention in its help that there is such a type of CM message present. But apparently, it's BCB.
Custom messages. Oh, if you are interested in the VCL source code to find the relevant content. There will be no small gains.
else if message.msg = Cm_visiblechanged Then
With the message do
Senddocknotification (MSG, WParam, LParam);
Finally, the dispatch method is called.
Dispatch (message);
End