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?
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?
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;
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;
private
or public
or published
areas. You made me catch this. That's why your post is the answer to my question. Others get upvotes from me. This post was indeed informative. Thanks everyone a lot. –
Wurst published
will break Delphi's form loading system. This is little beyond the scope of the original question, but event handler method will be bound at run-time to event property by the means of name lookup (stringly!) and this requires both of them to be published
(see TObject.FieldAddress and TObject.MethodAddress). –
Backdate 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;
;
–
Fit ;
is a fair price to pay, IMHO. –
Fit begin ; end;
which involves even less typing ;) –
Bootery 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.
© 2022 - 2024 — McMap. All rights reserved.