8

I was wondering if there is an equivalent to Visual Studio's #regions in RAD Studio.

We use Delphi and C++builder IDEs where I work and I would love to be able to use something like regions.

My coworkers and I have yet to find an equivalent way of grouping code... do you know of any?

Johan
  • 74,508
  • 24
  • 191
  • 319
stevosaurus
  • 557
  • 7
  • 18

3 Answers3

20

You can apply a special {$REGION 'Region Name'} directive to mark a "named" collapsible regions in the code editor.

To mark code as a region, surround it with the REGION and ENDREGION directives. You may include a caption that will be displayed when the code is folded and hidden.

Here's an exampe of the two (nested) regions:

{$REGION 'Iterate Panels'}
for j := 0 to StatusBar1.Panels.Count - 1 do
begin
  x := x + StatusBar1.Panels[j].Width;
  {$REGION 'Inner if Region'}
  if mpt.X < x then
  begin
    panel := j;
    Break;
  end;
  {$ENDREGION}
end;
{$ENDREGION}

To fold or unfold a region, click on the [+] (if expanded) or [-] (if collapsed) marker left to the $region directive. This will look:

alt text http://z.about.com/d/delphi/1/G/o/a/coderegions.gif

eKek0
  • 23,005
  • 25
  • 91
  • 119
5

For C++Builder, use

#pragma region [name]
and
#pragma end_region
, as described in the documentation.
Moritz Beutel
  • 1,931
  • 2
  • 15
  • 18
  • 1
    There is however a thing, at least when using C++ Builder, the IDE does not remember which regions you have folded, and have a nasty tendency of unfolding them whenever you edit other parts of the document. So each time you open the file you have to fold the regions again, if that is what you wish. – Tommy Andersen Aug 16 '09 at 19:49
  • Yes, that's quite annoying, and I think it's a bug. For folded classes/functions, this was fixed in C++Builder 2010, but not yet for #pragma region... – Moritz Beutel Aug 27 '09 at 13:56
  • C++Builder 2010 Update 4/5 fixes this for #pragma region as well. – Moritz Beutel Feb 04 '10 at 12:16
4

As an addition to eKek0's answer note that (at least in d2009) you can select the code lines that you want to put in a region, right click and choose Surround | Region. You'll be prompted for the region name.

MarkF
  • 1,616
  • 1
  • 17
  • 27