When writing components, there are often some events whose controls are in the component, and the code of an event must be written outside the component. Take the onclick event of a button as an example:
Set the following code in the class:
Private
Fonclick:Tpolicyevent;
Procedure clicktransfer (Sender: tobject); {tpolicyevent}
Publish
Property onclick: tpolicyevent read fonclick write fonclick;
In the implementation section:
Procedure class name. clicktransfer (Sender: tobject );
{Transfers lbuttonfind onclick event to the outside world .}
Begin
If assigned (fonclick) then
Fonclick (Self); {substitute self for subcomponent's sender .}
End; {clicktransfer}
Add a statement to create:
Constructor class name. Create (aowner: tcomponent );
Begin
Inherited create (aowner );
{Place your initim initialization code here .}
Buttonfind. onclick: = clicktransfer;
End;
In create, bind the onclick event of the control to clicktransfer.
So. When you add a self-made component to the window, an onclick event is displayed in the event list of the component.
The code in this event is executed when you press the button in the component. The key to its implementation is:
If assigned (fonclick) then
Fonclick (Self); {substitute self for subcomponent's sender .}
This statement means that if you write code in onclick when using this component, it will be executed.
2004/08/31 t