防止在保存时删除具有空主体的方法 [英] Prevent methods with empty bodies from deletion on save

查看:11
本文介绍了防止在保存时删除具有空主体的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一直按Ctrl+S 是我的一个很矛盾的习惯.不利的一面是,delphi 在保存时会删除空函数/过程.

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.

有没有办法防止 IDE 在保存时删除具有空主体的函数/过程?

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

推荐答案

根据 OP 请求从评论转换.我的评论太小了,无法回答,所以我将添加一些可能对 OP 来说已经很明显的细节.

这仅发生在事件处理程序中¹.立即写下它们或用 todo²

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

¹也就是说,事件处理程序设计的方法类,它们由 表单设计器(这包括数据模块设计器和任何其他安装的自定义设计器).授予您可能熟悉 C# 背景的代表.其他任何方式均需人工"管理.

¹ 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 项目 (Ctrl+Shift+默认键绑定中的 T)绝对比空白注释更好:

² 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;

可能的特殊情况

TActionAutoCheck 设置 must(参见 Sir Rufo 以了解运行时的另一种可能性)分配其 OnExecute 以便 Enabled.在这种情况下,在设计类中不可避免地会有这样的空白事件处理程序.示例:

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;

这篇关于防止在保存时删除具有空主体的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆