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

Disabling an event handler after its first exexcution

By , About.com Guide

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

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. 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.