How do Delphi7 pass an event to the component outside in writing a visual component?

xiaoxiao2021-03-06  83

In writing components, there are often some events, and their controls are in the component, and the code of one of them is written in the component. Take a button on the onclick event:

Set the following code in the class:

Private fonclick: TNotifyEvent; Procedure ClickTransfer (Sender: Tobject); {TNOTIFYEVENT} Publish Property OnClick: TNotifyEvent Read Fonclick Write Fonclick

In the implementation section: procedure class name .ClickTransfer (Sender: TObject); ClickTransfer {; {Transfers LButtonFind OnClick event to the outside world.} Begin if assigned (FOnClick) then FOnClick (Self); {Substitute Self for subcomponent's Sender.} End }

Add a statement in CREATE: Constructor class name .create (Aowner: Tcomponent); begin inherited create (aowner); {Place Your Custom Initialization Code Here.} ButtonFind.Onclick: = ClickTransfer;

In CREATE, the ONCLICK event of the control is bound to the ClickTransfer.

Then. In the window, you add a homemade component, there will be an onclick event in the component's event list.

In this incident, when you press the button in the component, it will be executed. Its execution is:

IF assigned (self); {Substitute Self for Subcomponent's sender.} This sentence is that if you use this component, you will be executed in its OnClick.

2004/08/31 T

转载请注明原文地址:https://www.9cbs.com/read-121405.html

New Post(0)