Preserve Code Folding When Reopening a Project

posted 13 Mar 2010, 17:06 by Delphi Basics
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. 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. Code folding enables the user to read and navigate their code more easily but, when the project is closed, all the regions are expanded.

In Delphi 2005, a feature was introduced to preserve the code folding preferences so that the folded code can be folded after reopening the project.
Tools - Options - Environment Options - Autosave options - Project desktop (check box) .

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. Folded code will stay folded when the project is reopened. :)

Read another article here:

Screenshot coming later.