Thursday, April 2, 2009

Delphi Tips and Tricks: Quickly Switching Between Chunks of Code

I learned this trick from Chuck Jazdzewski so it's a goodie but oldie and real simple.

If you are working on two chunks of code that you need to go between you can use a comment like this:


{Exit(0); //}Exit(1);

Remove the first curly brace and instantly and easily your code changes:
  
Exit(0); //}Exit(1);

There is also a version of this for C++:

//*
return 0;
/*/
return 1;
//*/


Remove the first slash and instantly and easily your code changes:

/*
return 0;
/*/

return 1;
//*/

5 comments:

Anonymous said...

better yet-- use (* *) to enclose large sections of code.

recent codegear musings have me worried that support for (* *) may disappear soon.

^/ is something i use more commonly now.

Edwin | The most handy mind mapping software said...

Great trick!

Chris Bensen said...

X-Ray,

But with the the comment trick I posted about it only takes on character change. Using (* *) is two locations and 4 characters.

I don't think you have to worry about (* *) going away as a comment style.

Alister Christie said...

I use the CTRL+/ a lot these days for commenting. It's very fast for adding and removing comments.

Chris Bensen said...

Alister,

CTRL + / is a very handy way to comment out code. However, my tip allows you to switch between two different pieces of code really fast.

Post a Comment