Show: Delphi C++
Display Preferences

Using Code Folding

From RAD Studio
Jump to: navigation, search

Go Up to How To Edit Code in the Code Editor

Code folding lets you collapse (hide) and expand (show) your code to make it easier to navigate and read. RAD Studio generates code that contains code folding regions, but you can add your own regions as needed. Code folding is on by default.

The following blocks of code can be folded/unfolded:

  • Type definitions
  • Function definitions
  • Namespaces (C++) and units (Delphi)
  • Preprocessor region directives (see information about regions below)
  • XML Documentation comments for Delphi code (triple-slash comments: ///)

To enable and disable code folding

  • To enable and disable code folding for the current session and subsequent sessions, use the Code Folding option on the Tools > Options > Editor Options dialog box.
  • To enable and disable code folding for the current edit session, press and hold Ctrl+Shift K+O.

If the code folding feature is disabled, then any collapsed code block is expanded and can no longer be collapsed (until code folding is enabled).

To collapse and expand code

You can collapse or expand code blocks in the following ways:

  • Click the minus or plus sign (-/+) to the left of a specific block;
  • Use key combinations (see below);
  • Use the Code Editor Context Menu entries Fold/Unfold (see below).

To collapse code

To collapse a specific code block, click the minus (-) sign to the left of the code block.

To collapse the nearest code block, you can:

  • Press and hold Ctrl+Shift K+E, or
  • Right-click the Code Editor and select Fold > Nearest.

Using the Code Editor context menu command Fold, you can collapse specific categories of code blocks: that is, regions, XML DOC comments, and so on. For more information, see Code Editor Context Menu.

To expand code

To expand a specific collapsed code block, click the plus (+) sign to the left of the code block.

To expand the nearest collapsed code block, you can:

  • Press and hold Ctrl+Shift K+U, or
  • Right-click the Code Editor and select Unfold > Nearest.

To expand all the collapsed blocks, you can:

  • Press and hold Ctrl+Shift K+A, or
  • Right-click the Code Editor and select Unfold > All.

To add a code folding region

In the Code Editor, use the following preprocessor directives to surround a block of code:

(The region is marked with a minus (-) sign.)

Delphi

See Regions.

{$REGION 'Optional text that appears when the code block is folded'}
 
// ...
 
{$ENDREGION}

C++

See #pragma region and #pragma end_region.

#pragma region optional text that appears when the code block is folded
 
// ...
 
#pragma end_region

See Also

Personal tools
RAD Studio 10.2 Tokyo
In other languages
Previous Versions
Assistance