1

I widely use {$Regions} in my units, but sometimes the VCL editor takes annoying decisions to automatically expand all regions. Is there any way to tell the editor not to expand regions that are collapsed unless I explicity do this by clicking on the + button?


Update from comments:

Unfolding occurs,

  1. with nested procs/funcs. Introducing a new nested "procedure" header. As soon as you type the 'p' character, all other nested procs/funcs are unfolded. This occurss also if, for instance, by mistake, you delete the "end" of any nested proc/func (or anything of the kind).
  2. with regions. If you start a comment with "{", the Region immediately below is unfolded. Starting a comment with "(*" provoques all Regions below to be unfolded and same applies to all procs/funcs under those Regions.
4

1 回答 1

1

不幸的是,这是 Delphi 的问题之一,至少从 Delphi XE 开始就存在,即使不是来自旧版本,也没有得到修复。

代码自动展开的原因是,只要 Error Insight 系统检测到您单元中的任何语法错误,它就会将该点以下的所有代码视为无效,从而展开该点以下的所有折叠代码。

到目前为止,我知道避免这种情况的唯一方法是禁用错误洞察。但这意味着在您尝试编译程序之前,您不会被警告任何潜在的语法错误。

但我真诚地希望 Embarcadero 能够尽快修复这个问题,因为它会使整个代码折叠系统变得无用,除非你禁用了 Error Insight,因为你花更多的时间再次折叠自动扩展的代码而不是编写任何新代码。

编辑:重现此的步骤(重现它的一种方式)

创建新应用程序

为您的表单或任何其他两种方法为 OnCreate 和 OnClose 创建两个新的偶数处理程序。

procedure TForm1.FormCreate(Sender: TObject);
begin

end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  //
end;

如果您创建了偶数处理程序,请确保在最低处理程序方法中至少有一些代码或至少有一个注释行,以便优化器不会自动删除“empy”事件处理程序。

现在在顶级事件处理程序中写入“Form”。您将看到如何自动扩展底部事件处理程序。

您将看到此时 delphi desent 甚至知道检测到语法错误的当前方法代码块何时何地结束。这也使得无法正确检测低于该点的任何代码块。

于 2014-10-17T21:38:57.557 回答