How does Delphi7 deliver an event to the external component in the preparation of a visual component?

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.