Mega Code Archive

 
Categories / Delphi / OOP
 

Disable an event handler

Title: Disable an event handler Question: Sometimes you want to disable an event handler after the FIRST time. E.g., you want to disable all clicks on a component AFTER THE FIRST CLICK, this is how you do it. Answer: Sometimes you want to disable an event handler after the FIRST time. E.g., you want to disable all clicks on a component AFTER THE FIRST CLICK: procedure ComponentOnClick; begin Button1.OnClick := nil; end; In the case of a button Onclick you obtain the same effect by disabling the button itself, and at the same time you give a visual feedback. So this trick only makes sense for other events and components.