Prevent methods with empty bodies from deletion on save

后端 未结 3 2083
后悔当初
后悔当初 2021-01-18 13:24

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 t

相关标签:
3条回答
  • 2021-01-18 13:41

    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;
    
    0 讨论(0)
  • 2021-01-18 13:56

    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;
    
    0 讨论(0)
  • 2021-01-18 14:00

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

    There is no option in the IDE to disable this behaviour.

    0 讨论(0)
提交回复
热议问题