Delphi tips:

Deleting an event handler

 
To quickly delete an event handler, simply delete the text from between the keywords begin and end. If there are declarations before the keyword begin (like const, var, type), also delete these. Let's say that you have an event handler that looks like this:

procedure TFormMain.Button1Click(Sender: TObject);
var
  S: string;
begin
  S := '123';
  Label1.Caption := 'Testing... ' + S;
  Edit1.Text := S;
end;

After removing the text:

procedure TFormMain.Button1Click(Sender: TObject);
begin
end;

Next, compile the project... and automagically, Delphi has completely removed the event-handler. Not only from the interface section, but also from the implementation and from the form-file (the .dfm file). That's a lot easier and quicker than manually removing all this stuff!


And here's a familiar story... From the Object Inspector, you ask Delphi to create empty procedures (templates) for the OnClick events of 3 buttons. You add your code to the first procedure and you do a quick test: F9 -- great, that works. But where have the event-handlers of the 2 other buttons gone? Right, Delphi has deleted them...

Tip: to keep an event-handler that is still empty, simply add a comment to it. Even an empty comment will do, like this:

procedure TFormMain.Button1Click(Sender: TObject);
begin
  //
end;

TOP   DelphiLand Club Membership  DC Library  Forum  Forum Archives  Crash Course Delphi  Tips  Source Code  Downloads  Links