Delphi XE2: Nested Comments, I want them!

Delphi XE2: Nested Comments, I want them!

I've had some troubles with nested "{" and "}" pairs aka curly-braces. Specifically, when I have a piece of code with an inline comment that I'd like to keep....

function ThisIsAFunction()
begin
   if (SomeFunction(Var1{used to use Var2})) then
      DoSomething();
end;

... But in debugging, I decided to comment a line out in this function. However, nest curly-braces don't seem to work and the IDE/compiler complains...

function ThisIsAFunction()
begin
{   if (SomeFunction(Var1{used to use Var2})) then
      DoSomething();}
end;

Sometimes, I want to comment out a section of code and mark it.. 

{$REGION 'OldCode'}
{
function ThisIsAFunction()
begin
{   if (SomeFunction(Var1{used to use Var2})) then
      DoSomething();}
end;
}
{$ENDREGION}

I always have to change my comments to "//" when I want to enclose them in "{". Sure wish I could just leave the "{" there and nest it inside another "{".

Comments

  1. You use
    {$IFDEF False}
    // your commented code goes here
    {$ENDIF}
    and i do {$DEFINE False} :P

    I use the shortcut CTRL + # for commenting multiple lines, I think its from GExpert.

    ReplyDelete
  2. I tend to select several lines and hit Ctrl+/, which comments/uncomments via //.  For me it's faster than navigating to and deleting two { } characters.

    ReplyDelete
  3. I use {} for real comments, // for commenting things out or for comments at the end of the line, and (* *) for big blocks. No problem to comment out the comments with Ctrl + #, which works on single lines and multiple lines, no GExpert needed. I guess Ctrl + # is specific to the German IDE, where it is used instead of Ctrl + / .

    ReplyDelete

Post a Comment