Code Editor
The Code Editor provides a convenient to view and modify your source code. It is a full-featured, customizable, ANSI editor that provides syntax highlighting, multiple undo capability, and context-sensitive Help for language elements. As you design the user interface for your application, Delphi 2005 generates the underlying code. When you modify object properties, your changes are automatically reflected in the source files. Because all your programs share common characteristics, Delphi 2005 auto-generates code to get you started. Do not modify the auto-generated code for the Initialize Components method. Doing so will cause your form to disappear when you click the Design tab. You can think of the auto-generated code as an outline that you can examine to create your program. The Code Editor provides the following features to help you write code:
Refactoring Code Insight Sync Edit Class completion Code browsing Code snippets Code folding To-Do Lists Keystroke macros Bookmarks Block commentsRefactoring
Refactoring is the process of improving your code without changing its external functionality. For example, you can turn a selected code fragment into a method by using the extract method refactoring. Delphi 2005 moves the extracted code outside of the current method, determines the needed parameters, generates local variables if necessary, determines the return type, and replaces the code fragment with a call to the new method. Several other refactorings, such as renaming a symbol and declaring a variable, are also available.
Sync Edit
The Sync Edit feature lets you simultaneously edit duplicate identifiers in code. If you select a block of code that contains duplicate identifiers, for example, label1, and click the Sync Edit Mode icon that appears in the left gutter, all of the duplicated identifiers are highlighted and the cursor is positioned to the first identifier. As you change the first identifier, the same change is performed automatically on the other identifiers.
Code Insight
Code Insight refers to a subset of features embedded in the Code Editor that aid in the code writing process. These features display context-sensitive pop-up windows and provide the following services:
Help identify common statements you wish to insert into your code. Assist in the selection of properties and methods. Display events available for a particular class. Provide view declaration information for identifiers.To enable and configure Code Insight features, choose Tools Options and click Code Insight.
Class Completion
Class completion simplifies the process of defining and implementing new classes by generating skeleton code for the class members that you declare. By positioning the cursor within a class declaration in the interface section of a unit and pressing CTRL+SHIFT+C, any unfinished property declarations are completed. For any methods that require an implementation, empty methods are added to the implementation section.
Code Browsing
While using the Code Editor to edit a VCL Form application, you can hold down the CTRL key while passing the mouse over the name of any class, variable, property, method, or other identifier. The mouse pointer turns into a hand and the identifier appears highlighted and underlined; click on it, and the Code Editor jumps to the declaration of the identifier, opening the source file if necessary. You can do the same thing by right-clicking on an identifier and choosing Find Declaration. Code browsing can find and open only units in the project Search path or Source path, or in the product Browsing or Library path. Directories are searched in the following order:
1. The project Search path ( Project Options Directories/Conditionals).
2. The project Source path (the directory in which the project was saved).
3. The global Browsing path ( Tools Options Library).
4. The global Library path ( Tools Options Library).
The Library path is searched only if there is no project open in the IDE. Code browsing cannot find identifiers declared in new, unsaved unit files, and it does not work in package projects.
Code Snippets
Code snippets are commonly used programming statements, such as if, while, and for statements, that you can insert into your code. When the Code Editor is open, you can double-click a code snippet on the Tool Palette to add it to your code. You can also create your own code snippets by selecting code in the Code Editor, pressing the ALT key, and dragging the code to the Tool Palette.
Code Folding
Code folding lets you collapse sections of the code to create a hierarchal view of your code and to make it easier to read and navigate. The collapsed code is not deleted, but hidden from view. To use code folding, click the plus and minus signs next to the code.
To-Do Lists
A To-Do List records tasks that need to be completed for a project. After you add a task to the To-Do List, you can edit the task, add it to your code as a comment, indicate that it has been completed, and remove it from the list. You can filter the list to display only those tasks that interest you.
Keystroke Macros
You can record a series of keystrokes as a macro while editing code. After you record a macro, you can play it back to repeat the keystrokes during the current IDE session. Recording a macro replaces the previously recorded macro.
Bookmarks
Bookmarks provide a convenient way to navigate long files. You can mark a location in your code with a bookmark and jump to that location from anywhere in the file. You can use up to ten bookmarks, numbered 0 through 9, within a file. When you set a bookmark, a book icon is displayed in left gutter of the Code Editor.
Block Comments
You can comment a section of code by selecting the code in the Code Editor and pressing CTRL+/ (slash). Each line of the selected code is prefixed with // and will be ignored by the compiler. Pressing CTRL+/ will add or remove the slashes, based on whether the first line of the code is prefixed with //. When using the Visual Studio or Visual Basic key mappings, use CTRL+K+C to add and remove comment slashes.