1. Home
  2. Computing & Technology
  3. Delphi Programming

Create Collapsible Code Blocks in Delphi Code Editor
Directives {$REGION 'Caption'} and {%ENDREGION} help you maintain your code

By Zarko Gajic, About.com

Collapsible Code Regions in Delphi Code Editor

Collapsible Code Regions in Delphi Code Editor

In Delphi 2006 (both Win32 and .Net) 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.

Delphi tips navigator:
» TListView.SubItem.Hint : How to Display Custom Hints for TListView Sub Items
« Use an Icon for a Glyph on a TBitBtn Delphi control with the help of TImageList

More Delphi Programming Quick Tips
Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. Delphi 2007 Tips
  7. Create Collapsible Code Blocks in Delphi Code Editor using the {$REGION} directive

©2009 About.com, a part of The New York Times Company.

All rights reserved.