Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent methods with empty bodies from deletion on save

It's quite a contradictory habit of mine to press Ctrl+S permanently. The negative side is that delphi deletes empty functions/procedures on save.

Is there a way to prevent IDE from deleting functions/procedures with empty bodies on save?

like image 397
horgh Avatar asked Nov 23 '12 07:11

horgh


2 Answers

Converted from the comment as per OP request. My comment is too tiny for an answer, so I'm going to add few details maybe already obvious to an OP.

This happens with event handlers only¹. Write them without delay or comment them with todo²

¹ That is, event handlers are methods of design class and they are created, listed and deleted (if caught empty when saving or compiling) by the form designer (this include data module designer and any of other custom designers installed). Confer to delegates you probably familiar with from C# background. Any other methods are subject to "manual" management.

² TODO items (Ctrl+Shift+T in default keybinding) are definitely better than just blank comments:

procedure TForm1.MagicButton1Click(Sender: TObject);
begin
  { TODO -ctomorrow : I'm going to write the code, I promise! }
end;

Possible special case

TAction with AutoCheck set must (see the comment from Sir Rufo below for another possibility at run time) have its OnExecute assigned in order to be Enabled. In this case it is inevitably to have such blank event handlers within design class. Example:

procedure TMonitor.AutoCheckActionExecute(Sender: TObject);
begin
  // dummy stub
  { DONE -crefactor : merge with other stub(s) }
end;
like image 69
OnTheFly Avatar answered Oct 20 '22 23:10

OnTheFly


Just add an empty comment like //

begin 
//
end;

an other way would by moving the declaration to the published part

type
  TForm5 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject); // will be removed if empty
  private
    { Private-Deklarationen }
  public
  published
    procedure Button2Click(Sender: TObject); // will not be removed if empty

    { Public-Deklarationen }
  end;
like image 45
bummi Avatar answered Oct 21 '22 00:10

bummi