Read an Excerpt
The Delphi 4 Integrated
 The AppBrowser editor
 The Code Insight technology
 Designing forms
 The Project Manager
 Delphi files
 The Object Repository
In a visual programming tool such as Delphi, the role of the environment is certainly important, at times even more important than its programming language. Delphi 4 provides an all-new visual development environment, and this chapter covers its new features in detail. This chapter isn't an extensive tutorial, but mainly a collection of tips and suggestions aimed at the average Delphi user. In other words, it's not for newcomers. I'll be covering the new features of the Delphi 4 Integrated Development Environment (IDE) and some of the advanced and/or little-known features of the Delphi 3 environment as well, but in this chapter I won't be providing a step-by-step introduction. Throughout this book I'll assume you already know how to carry out the basic hands-on operations of the IDE, and all the chapters after this one focus on programming issues and techniques.
If you are a beginning programmer, don't be afraid. The Delphi Integrated Development Environment is quite intuitive to use. Delphi itself includes a manual (available in Acrobat format on the Delphi CD) with a tutorial that introduces the development of Delphi applications.
Here is your first tip. In Delphi 4 you can open a file or a project by double-clicking on a file in the Windows Explorer. Although you could do the same thing in Delphi 3, this operation opened a new copy of the IDE, which took a lot of time. Delphi 4, instead, opens a PAS or DFM file in the current copy of the IDE. When you select a DPR file, Delphi closes the current project after asking you to save it. (Note, though: When you already have a dialog box open in Delphi the dialog box is hidden by the new files you open, but you cannot use the Delphi menu items and toolbars until you find and close that dialog box.)
Different Editions of Delphi 4
Before delving into the details of the Delphi programming environment, let's take a side step to underline two key ideas. First, there isn't a single version of Delphi 4; there are many of them:
* The basic version (the "Standard" edition) is aimed at Delphi newcomers and casual programmers.
* The second level (the "Professional" edition) is aimed at professional developers. It includes all the basic features, plus extended database programming support, some Internet support, and some of the external tools. This book generally assumes you are working with the Professional edition.
* The full-blown Delphi (the "Client/Server Suite" edition) is aimed at developers building enterprise applications. It includes extensive Web server support, SQL Links for native Client/Server BDE connection, the three-tier support, and many other tools such as the SQL Monitor. Parts of some chapters cover features included only in the Client/Server Suite; these sections are specifically identified.
* There are also higher-end editions of Delphi offering support for AS/400 (called "Delphi/400") and Entera (called "Delphi Enterprise"). This book does not cover any features available only in those editions.
Besides the different editions available, there are a number of ways to customize the Delphi environment. In the screen illustrations throughout the book, I'll try to use a standard user interface (as it comes out of the box); however, I have my preferences, of course, and I generally install many add-ons, which might be reflected in some of the screen shots.
The AppBrowser Editor
The editor included with Delphi 4 retains all the features of the Delphi 3 editor, but it adds a totally new perspective to reading and writing the source code of an application. (That's probably what inspired the Borland/Inprise marketing people to give the editor a new name, AppBrowser.) There are basically three fundamental innovations: A Code Explorer window (which lists all the definitions of a unit), support for navigation (similar to that of a Web browser), and Class Completion (a new code-generation technology).
Besides these specific innovations, the editor now shares docking support with the rest of the Delphi 4 environment. This means you can dock most of the windows on the side of the editor. These dockable windows include the Code Explorer, the Object Inspector, and the Project Manager. You can let each window have a specific area (as in Figure 1.1), or turn them into a multi-page view.
The Delphi editor allows you to work on several files at once, using a "notebook with tabs" metaphor. You can jump from one page of the editor to the next by pressing Ctrl+Tab (or Shift+Ctrl+Tab to move in the opposite direction). There are a number of environment options that affect the editor, mostly located in the Editor Options, Editor Display, and Editor Colors pages of the Environment Options dialog box. You have to go to the Preferences page, however, to set the editor's AutoSave feature, which saves the source code files each time you run the program.
Besides using cut and paste commands, the Delphi 4 editor, like the Delphi 3 editor, allows you to move source code by selecting and dragging words, expressions, or entire lines of code. You can also copy text instead of moving it, by pressing the Ctrl key while dragging.
The Code Explorer
The Code Explorer window, which is generally most useful when it's docked on the side of the editor, simply lists all of the types, variables, routines, and units defined in a unit. For complex types, such as classes, the Code Explorer can list detailed information including a list of fields, properties, and methods. All the information is updated as soon as you start typing in the editor. You can use the Code Explorer to navigate in the editor. If you double-click one of the entries in the Code Explorer, the editor jumps to the corresponding declaration.
While all that is quite obvious after you've used Delphi 4 for a few minutes, there are some features of the Code Explorer that are not so intuitive. One important point is that you have full control of the layout of the information, and you can reduce the depth of the tree usually displayed in this window by customizing the Code Explorer. Reducing the depth of the tree can help you make your selections more quickly. You can configure the Code Explorer by using the corresponding page of the Environment Options, as shown in Figure 1.2.
The most important settings are probably those related to classes. The definitions related to a class can be arranged in three ways:
* According to the private, protected, public, and published categories
* According to the methods and fields categories
* All together in a single group
As each item of the Code Explorer tree has an icon marking its type, arranging by field and method seems less important than arranging by access specifier. My preference is to show all items in a single group, as this requires the fewest mouse clicks to reach each item. Selecting items in the Code Explorer, in fact, provides a very handy way of navigating the source code of a large unit. When you double-click on a method in the Code Explorer, the focus moves to the definition in the class declaration (in the interface portion of the unit). You can use the Ctrl+Shift combination with the up or down arrow keys in Delphi 4 to jump from the definition of a method or procedure in the interface portion of a unit to its complete definition in the implementation portion (or back again).
Editing in the Code Explorer
The Code Explorer is not only an output and browsing tool. In fact, you can use it for entering new items in each category, as shown in Figure 1.4. Actually, the type of the new item generally depends on what you type: A name that starts with the procedure or function keywords is automatically considered a method, while a name followed by a semicolon and a data type is considered a field.
Field, methods, public, private ...? If you're not familiar with the terminology of the Object Pascal language, you'll find good coverage of these terms in Chapter 3. I've used them here without explaining them simply because most readers of this book probably have at least some exposure to Delphi and its programming language.
The editing capabilities of the Code Explorer are too limited to provide a real advantage compared to the usual method (editing in the source code window). It would be nice to have dragging capabilities, for example, to move a field or method to a different visibility section or copy it to another class.