Jamo
Jamo

Reputation: 3258

Collapsing If-Then-Else statements in code editor (Delphi 2007)

Every once in a while I'm editing some long pair of if-then-else statements (or worse, nested if-then-else statements) , like, say, this:

  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;

...and I find myself wanting to "collapse" the first begin-end pair, to bring up the lower "else" part (usually because I'm referring to something above the if-then statemnent. Maybe so it would just say "begin..." and have [+} sign to the left of it to expand it out again.

I've explored the "fold" functions in the IDE, but none of the commands seem to do this. It seems like my CodeRush for my old D6 did this, but I could be imagining things. (I have a very active imagination...).

Do any of the IDE plug-ins like Castalia (or some other one) do this?

Upvotes: 1

Views: 2367

Answers (3)

skamradt
skamradt

Reputation: 15538

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.

Upvotes: 1

Rob Kennedy
Rob Kennedy

Reputation: 163267

Use the refactoring tools to move the conditional branches' code into separate functions. Then you won't need to fold anything. You might also find that you can merge code that's common to the two branches, such as that call to FinallyWrapUpThisBit.

Upvotes: 7

Francesca
Francesca

Reputation: 21640

With plain Delphi out of the box, you would have to surround your begin...end with

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

which can be done through a code template...

I remember Castalia for the nice colored visualization of code blocks (begin..end) but I don't remember if it was foldable.

Upvotes: 7

Related Questions