1

每隔一段时间,我都会编辑一些长的 if-then-else 语句(或者更糟糕的是,嵌套的 if-then-else 语句),例如:

  if A < B then 
  begin
    DoSomething; 
    DoSomethingElse;
    {...and more statements going on and on and on...}
    FinallyWrapUpThisBit;
  end 
  else 
  begin
    DoThis;
    DoThat;
    {...and more statements going on and on and on...}
    FinallyWrapUpThisBit;
  end;

...而且我发现自己想要“折叠”第一个开始-结束对,以调出较低的“else”部分(通常是因为我指的是 if-then 语句之上的内容。也许它会这么说“开始...”并在其左侧添加 [+} 符号以再次展开。

我已经探索了 IDE 中的“折叠”功能,但似乎没有一个命令可以做到这一点。似乎我的旧 D6 的 CodeRush 做到了这一点,但我可以想象事情。(我的想象力很活跃……)。

像 Castalia(或其他一些)这样的任何 IDE 插件都可以做到这一点吗?

4

3 回答 3

7

使用开箱即用的普通 Delphi,您将不得不围绕您的开始...结束

  {$region 'begin...end'}
  .... 
  {$endregion}

这可以通过代码模板完成...

我记得 Castalia 对代码块进行了漂亮的彩色可视化(begin..end),但我不记得它是否可折叠。

于 2009-04-07T01:49:30.060 回答
7

使用重构工具将条件分支的代码移动到单独的函数中。然后你就不需要折叠任何东西了。您可能还会发现您可以合并两个分支共有的代码,例如对FinallyWrapUpThisBit.

于 2009-04-07T02:43:16.623 回答
1

Another big helper here would be CNPack. It is a wizard which installs into Delphi and will colorize your begin/end pairs, making it MUCH easier to follow the code. It doesn't exactly do code folding, for that you need to use the {$REGION} {$ENDREGION} tags.

于 2009-04-13T23:27:08.897 回答