On the surface, the Delphi editor does not appear to have changed much for version 7 of the IDE. However, behind the scenes, it's an entirely new tool. In addition to using it to process files from the Object Pascal language (or Delphi language, as Borland now likes to call it), you can now use it to process other files developed for Delphi (such as SQL, xml, HTML, and XSL files) files, as well as files in other languages (including C++ and C#). XML and HTML editing are already available in Delphi 6, but there are significant changes in this version. For example, when editing an HTML file, you have support for syntax highlighting and code completion.
The editor settings used on each file (including the behavior of keys like Tab) depend on the extension of the file being opened. You can configure these settings in the new Source Options page of the new Editor PRperties dialog box, as shown in Figure 1.4. This feature has been extended and made more open, so you can provide syntax highlighting for other programming languages by providing a DTD for XML-based file formats or writing a custom wizard. Another feature of the editor, code templates, is now a language feature (your predefined Delphi templates will have no meaning in HTML or C#). ? ? ?
| Comment | C# is a new language introduced by Microsoft in its .NET architecture. Borland is expected to support C# in its own .NET environment, currently codenamed Galileo. |
Considering only the Delphi language, the editor included in the IDE has not changed much in recent versions. However, it has some features that many Delphi programmers don't know about and don't use, so I thought it was worth a brief examination of it.
The Delphi editor allows you to work on several files at the same time, using a "notebook with tabs" metaphor. You can jump from one page of the editor to an adjacent page by pressing the Ctrl+Tab key combination (or Ctrl+Shift+Tab to move in the opposite direction). You can drag-and-drop the tabs labeled with unit names in the upper part of the editor to change their order, so that at any given time you can use a single Ctrl+Tab to move between the units you are working on. The editor's shortcut menu also has a Pages command that lists all available pages in a submenu (a very convenient feature when many units are loaded).
You can also open multiple editor windows, each with multiple tabs. Doing this is the only way to see the source code of two units next to each other. ((In fact, when I need to compare two Delphi units, I always use Beyond Compare—www.scootersoftware.com—one of the best low-cost comparison utilities written in Delphi.)
Several options affect the editor, as you can see in the Editor Properties dialog box in Figure 1.4. However, you have to go to the Preferences page of the Environment Options dialog box (see Figure 1.2) to set the editor's AutoSave feature. This option forces the editor to save all source program files when you run the program, preventing data loss in the unlikely event that the program crashes in the debugger.
Delphi's editor provides many commands, including some starting with its WordStaremulation ancestry (an early Turbo Pascal compiler). I won't discuss the various editor settings as they are very intuitive and are described in the online help. However, note: the help page describing keyboard shortcuts is as a whole understandable only if you look for the shortcuts index entry.
| Skill | One tip to remember is that using the Cut and Paste commands are not the only ways to move source code. You can also select and drag words, expressions, or entire lines of code. Additionally, you can copy text by holding down the Ctrl key while dragging, rather than moving it. |
The Code Explorer window, which is typically reduced on the editing side, lists all types, variables, and transactions defined in a unit, plus other units in which the declarations appear to be in use. For complex types, such as classes, Code Explorer can list detailed information, including a list of fields, properties, and methods. Once you start typing in the editor, all information is updated.
You can use Code Explorer to navigate your edits. If you double-click on one of the inputs in Code Explorer, the editor jumps to the corresponding declaration. You can also modify variable, property, and method names directly in Code Explorer. However, if you want a visual tool to use when working on your category, you will see that ModelMaker offers many more features.
Although all of this functionality is obvious after you've been using Delphi for a few minutes, some features of Code Explorer are not so intuitive. You have ample control over the layout of your information. At the same time, you can reduce the depth of the tree normally displayed in this window by customizing the Code Explorer (collapse the tree to help you formulate your choices more quickly). You can configure Code Explorer by using the environment option of the corresponding page, as led to number 1.5.