1. Technology

Preserve Code Folding When Reopening a Project

Collapse and Stay Collapsed!


Preserve Code Folding in Delphi Code Editor

Preserve Code Folding in Delphi Code Editor

Introduced in Delphi 8, code folding is a feature of the Delphi IDE which lets you collapse (hide) and expand (show) your code to make it easier to navigate and read.

By default, Delphi Code editor adds folding regions to classes, function and procedures and unit section. By default, all regions are expanded.

Note the little "-" sign to the left of a procedure declaration line. Click it to collapse the procedure implementation code, click it again to expand it.

Custom collapsible code blocks in Delphi Code Editor can be easily created using the "{$REGION 'Caption'}" and "{$ENDREGION}" directives.

I've Closed My Project: All Regions are Expanded :(

If you collapse a region and close the project, next time you open the project (a code unit) the "collapsed" code block will be expanded.

I love code folding - it really lets me read and navigate my code more easily. BUT, when I close the project, all my regions are expanded :(

Is there a way to preserve your code folding preferences? Can a folded code be folded after reopening your project?


Tools - Options - ... - Autosave Project Desktop!

There's an option under the "Environment Options" element of the Tools - Options dialog box called "Project Destop" in the "Autosave options" group.

That is: Tools - Options - Environment Options - Autosave options - Project desktop (check box) .

Here's what the Help has to say about the "Project desktop" ceck box (when checked): Delphi saves the arrangement of your desktop when you close a project or close the IDE. When you later open the same project, all files opened when the project was last closed are opened again, regardless of whether they are used by the project.

There's more to what the Help states: folded code will stay folded when the project is reopened.

Therefore: to preserve your code folding preferences (per unit) - for the folded code to stay folded - turn on the "Project desktop" check box under "Autosave options".

Delphi tips navigator:
» Format XML Data - Properly Indent TXMLDocument XML Tags Without doNodeAutoIndent
« Rename a Directory / Folder Using Delphi Code

©2014 About.com. All rights reserved.