1. Home
  2. Computing & Technology
  3. Delphi Programming

Disabling an event handler after its first exexcution

By Zarko Gajic, About.com

Have you ever wanted to keep an event from firing once it has executed? Simply set the event handler method to nil in the body of the method. For instance, let's say you want to disable an OnClick for a button once the user has pressed it. Here's the code to do that:

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure Button1OnClick;
begin
  //code to be done only once!

  Button1.OnClick := NIL;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» How to use a dialog window to select a folder
« How to add a button to the IE Toolbar

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2002 Delphi Tips
  7. Disabling an event handler after its first exexcution

©2009 About.com, a part of The New York Times Company.

All rights reserved.