Internal]
http://delphi.ktop.com.tw/topic.asp?topic_id=55494
Try to analyze TFORM1.PAGECONTROL1Change (Sender: TOBJECT):
Let's see what is onchange? It is a changing event (event). Event is a special attribute. Since ONCHANGE is attribute, it is certainly a special type of data, what is the type of information? Press F1 to find it in the Help of Delphi: Property Onchange: TNOTIFYEVENT; otherwise, onchange is the data of the TNotifyEvent type. Take a look at TNOTIFYEVENT, find such a type: Type TnotifyEvent = procedure (sender: TOBJECT) OF Object looks so strange, because TNOTIFYEvent adds an Object keyword, and the role of Object is only the variables can only pass the object. Create. So now you can say: TNOTIFYEVENT is a method type
Look again (Sender: TOBJECT), where Sender is a TOBJECT type parameter, which tells Delphi which component receives this event and calls the corresponding process. We can write a single event handling control code, handle multiple components through the Sender parameter and if ... then ... statement or CASE statement. The value of the element that has occurred has already given the Sender parameter. One of the purposes of this parameter is that the reserved word is can be used to test the Sender to find the type of component that calls this event to process the control code, for example::
Procedure TFORM1.XXX (Sender: TOBJECT);
Begin
Sender if teditin
ShowMessage ('this is a editbox');
IF (sender is TLabel) THEN
ShowMessage ('this is a label');
END;
The second use of the Sender parameter is: combined with the AS operator to convert subclasses to the subclass of a certain parent class into the parent class, for example: a TEDIT element and a TMEMO in an Formo Components, they are actually derived from TCUStomedit classes. If I want to provide the same processing for one of the two, I can point the two event controls to custom procedures YYY:
Procedure TFORM1.YYY (Sender: TOBJECT);
Begin
(Sender as tcustomedit) .Text: = 'this is some demo text';
END;
In the process, the AS operator enforces the TEDIT class and TMEMO classes to TCUSTOMEDIT classes, and the properties of the TCUStomedit class are assigned. Note that this conversion must comply with the hierarchical relationship between Delphi!
Through the above analysis, it is not difficult to understand the methods of William and T.J.B FORM1.PAGECONTROL1CHANGE (Form1.PageControl1).
The younger brother is also a gentleman, and the fallacy is definitely, please refer to you, thank you.