📄 ch09.htm
字号:
<P>The Debugging section of the Compiler page of the Project Options dialog box controlshow the compiler generates code for debugging sessions. When the Debug informationoption is enabled, Delphi generates debug information for the project. If you donot generate debug information, you will not be able to stop on breakpoints and inspectvariables during debugging. Put another way, you can't debug your program unlessyou tell Delphi to generate debug information.</P><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> If you change any of the options on the Compiler page, you should do a build immediately following the change. This will ensure that all units are rebuilt using the same compiler settings. <HR></BLOCKQUOTE><H4>Messages</H4><P>The Messages section determines whether you want the compiler to report hintsand warnings after compiling. I always leave both the Show Hints and Show Warningsoptions on. Hints and warnings should not be ignored in the long term (in the shortterm, you can ignore warnings that you know are due to temporary conditions in yourcode). Usually, compiler warnings can, and should, be resolved. Learn to treat hintsand warnings as errors. Quality code compiles without warnings.</P><P><H3><A NAME="Heading11"></A>The Linker Page</H3><P>The Linker page of the Project Options dialog box is where you set options thatspecify how you want the linker to operate. Until you become very familiar with Delphi,you can leave this page alone and accept the default settings. Figure 9.6 shows theLinker page of the Project Options dialog box. The options available on this pageare explained in the following sections.</P><P><A HREF="javascript:popUp('28670906.gif')"><B>FIGURE 9.6.</B></A><B> </B><I>ProjectLinker options.</I></P><P><I></I><H4>Map File</H4><P>The Map File settings control whether a map file is generated and how much detailis included in it. A map file is an advanced debugging tool and is something thatyou will not likely use until you get further into Delphi. For that reason, I won'tgo into more detail on the Map File options.</P><P><H4>EXE and DLL Options</H4><P>The EXE and DLL Options section determines the type of executable file producedby Delphi for an application project. When the Generate Console Application checkbox is checked, Delphi produces a console application as opposed to a GUI application.</P><P>The Include TD32 Debug Info option causes the linker to link the debug informationinto the EXE or DLL. ("TD32" refers to the 32-bit version of the venerableold Turbo Debugger. TD32 is an advanced standalone debugger that used to ship withBorland C++ products and with some versions of Delphi.) Some debugging utilitiesuse debug information in TD32 format. TurboPower's Memory Sleuth, for example, requiresTD32 debug information to be present in the EXE. Turn this option on when using programslike Memory Sleuth.</P><P>The Include Remote Debug Symbols option generates the debug symbols necessaryfor remote debugging of Web broker applications.</P><P><H4>Linker Output</H4><P>The Linker Output section determines what type of compiled binary file the linkershould produce. Normally the linker produces DCU files (the default for Delphi applications).You might, however, want to generate C or C++ object files (OBJs) rather than DCUs,thereby allowing your Pascal units to be used with a C or C++ program built withBorland C++Builder.</P><P><H4>Memory Sizes</H4><P>The Memory Sizes section can be ignored by all but the most advanced users. Thedefault values are acceptable for all applications. In some cases, you might changethe Image base address when building a DLL, but doing so is rarely necessary.</P><P><H4>Description</H4><P>The EXE Description field is used to specify a string that will be embedded inthe application. This field is sometimes used to add copyright information to anEXE or DLL. Most of the time, you will use version info to store copyright informationin a file rather than using the EXE Description field on this page. Version infois described later in the section "The Version Info Page."</P><P><H3><A NAME="Heading12"></A>The Directories/Conditionals Page</H3><P>The Directories/Conditionals page of the Project Options dialog box is where youset the directories that your project uses to find library files. Figure 9.7 showsthe Directories/ Conditionals page. The fields on this page are described in thefollowing sections.</P><P><A HREF="javascript:popUp('28670907.gif')"><B>FIGURE 9.7.</B></A><B> </B><I>TheDirectories/ Conditionals page.</I></P><P><I></I><H4>Directories</H4><P>The fields in this section determine where Delphi can find various source filesduring compilation of the project. It also contains fields that determine where certainfiles created by the compiler and linker will be placed during a build of the project.</P><P>The Output Directory field is used to specify the directory where the final executablefile or DLL will be placed. The Unit Output Directory determines where the DCU fileswill be placed for each unit compiled. The Search Path field is used to specify thedirectories where any additional libraries needed to build the project can be found.The Debug Source Path field is used to specify the path to any source units thatyou want to debug, but which are not in the current project's directory. For example,if you want to step into a DLL while debugging, you have to enter the path to theDLL's source code in this field. The BPL Output Directory and the DCP Output Directoryfields specify where the BPL and DCP files should be placed when building a package.</P><P>Note that a small button with an ellipsis on it appears next to several of thefields on the Directories/Conditionals page. Clicking this button displays an editorthat enables you to add, remove, or rearrange the items in a particular field. Figure9.8 shows this dialog box while editing the Search Path field.</P><P><A HREF="javascript:popUp('28670908.gif')"><B>FIGURE 9.8.</B></A><B> </B><I>TheDirectories editor dialog box.</I></P><P><I></I><H4>Conditionals</H4><P>You use the Conditional Defines field to specify any defines that you want toadd at the project level. For example, let's say you have code in your project thatwill be compiled only if the symbol TRIALRUN is defined. In that case, you wouldadd TRIALRUN to the Conditional Defines field. If you have more than one symbol todefine, make sure that each symbol is separated by a semicolon.</P><P><H4>Aliases</H4><P>The Unit Aliases field is used to specify any unit aliases. For example, Delphi1 used units called WinTypes.pas and WinProcs.pas for all Windows-specific code.Delphi 2, 3, and 4 use a unit called Windows.pas in place of WinTypes and WinProcs.The Unit Aliases field aliases WinTypes and WinProcs to the Windows unit. In thiscase, aliasing enables programs written in Delphi 1 to compile in Delphi 4 withoutmodification of the uses list.</P><P><H3><A NAME="Heading13"></A>The Version Info Page</H3><P>The Version Info page enables you to set the version information for your applications.Version information is stored in your program's EXE file or in a DLL or ActiveX file.It is used by installation programs to determine whether a file being installed isolder or newer than the file it is replacing.</P><P>Version info has other uses as well. You can view the version information fora file from Windows Explorer. Just right-click the file and choose Properties fromthe Explorer context menu. When the Properties dialog box comes up, click the Versiontab to view the version information for the file. Figure 9.9 shows the Propertiesdialog box displaying version information for the Database Desktop utility that comeswith Delphi.</P><P><A HREF="javascript:popUp('28670909.gif')"><B>FIGURE 9.9.</B></A><B> </B> <I>TheProperties dialog box showing version information for DBD32.EXE.</I></P><P>Figure 9.10 shows the Version Info page of the Project Options dialog box. Atthe top of the page is a check box labeled Include Version Information in Project.When this check box is checked, version information will be included in the project'sexecutable file. When this check box is not checked, version information is not includedin the project, and the rest of the page is disabled.</P><P><A HREF="javascript:popUp('28670910.gif')"><B>FIGURE 9.10.</B></A><B> </B><I>Versioninformation for your projects can be supplied on the Version Info page.</I></P><P>The remaining fields on the Version Info page are used to specify the variouspieces of version information. The Major Version, Minor Version, Release, and Buildfields work together to form the file version number. The version number of the filein Figure 9.10 is version 2.0, build 0. If you check the Auto-Increment Build Numberoption, the build number will automatically increment by one each time you performa build.</P><P>The Module Attributes section can be used to determine any special attributesyou want specified for the file. The Language section enables you to select a localeidentifier for the file. For more information on the possible values for the LocaleID field, see the Windows API online help under the topic "Language Identifiersand Locales."</P><P>The table at the bottom of the Version Info page can be used to set a varietyof information. This information includes your company name, the file description,the internal name of the file, the legal copyright or trademark information, theproduct name, product version, and any comments you want to add.</P><P>You can provide information for any of these fields or none at all (the FileVersionfield is set based on the fields in the Module Version Number section). You can evenadd your own custom version information fields. To add a custom version info field,simply click in the version info table and scroll to the end of the table using thedown-arrow key. Type the down-arrow key once more and a dialog box will be displayedasking you for the version key to add. Supply a key name and that key is added tothe version info for the project. Adding version information to a project has neverbeen so easy!</P><P><H3><A NAME="Heading14"></A>The Packages Page</H3><P>The Packages page is where you determine the type of linking that your projectswill use. The top part of the page enables you to add or remove design packages,but that really doesn't have anything to do with the current project. The only optionthat pertains to the current project is the Build with Runtime Packages check box.</P><P>When this option is selected, your application will use dynamic linking of theVCL and any third-party components. This means that your executable file will besmaller, but you will have to be sure to ship the correct packages with your application.When this check box is off, your application uses static linking. <I>Static linking</I>means that any VCL code and the code from any third-party components that your applicationuses is linked directly into your executable file. Packages were discussed in detailyesterday in the section "Using Packages." Figure 9.11 shows the Packagespage of the Project Options dialog box.</P><P><A HREF="javascript:popUp('28670911.gif')"><B>FIGURE 9.11.</B></A><B> </B><I>ThePackages page.</I></P><P><I></I><H2><A NAME="Heading15"></A>The Delphi Code Editor</H2><P>There is no question that Delphi is highly visual in nature--that's one of thegreat benefits of programming with Delphi. Still, any program of any significancewill have a great deal of code that must be written by hand. After you get the UIpart of your application written with Delphi's impressive visual tools, you'll likelyspend a long stretch with the Delphi Code Editor. The Code Editor has some featuresyou'll learn to appreciate when you discover them.</P><P>In this section, you learn about the following:</P><UL> <LI>Basic editor operations <P> <LI>Specialized editor features <P> <LI>The Code Editor context menu <P> <LI>Changing the editor options</UL><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> The Delphi Code Editor enables you to choose from four keyboard-mapping configurations: Default, IDE Classic, BRIEF, and Epsilon. The rest of this chapter assumes Default keyboard mapping. If you are already familiar with one of the other keyboard mapping configurations, you can ignore any references to specific keystrokes. <HR></BLOCKQUOTE><H3><A NAME="Heading16"></A>Basic Editor Operations</H3><P>I'm going to assume that you know enough to be able to enter and delete text,highlight text with the mouse, cut, copy, paste, and so on. I won't spend any timegoing over functions at that level.</P><P>When it comes right down to it, the Delphi Code Editor is a typical code editor.It features syntax highlighting, which makes identifying keywords, strings, numericconstants, and comments at a glance easy. You'll look at setting the editor preferencesa little later.</P><P>The Code Editor is a tabbed window. You can open as many editor windows as youlike; each window will be represented by a tab along the top of the editor windowthat will display the name of the file. To switch to a source file, simply clickthe tab corresponding to the file you want to view. If more tabs exist than can bedisplayed at one time, scroll buttons will appear so that you can scroll among thetabs.</P><P>The status bar at the bottom of the Code Editor gives status information (obviously).The current line number and the cursor position on the line are reported in the leftpanel of the status bar. If the file has changed since it was last saved, the statusbar will say Modified in the center panel of the status bar. The right panel of thestatus bar shows the current mode, either Insert or Overwrite. If the file has beenset to read-only, this panel will say Read Only.</P><P>The editor window has a gray strip in the left margin that is called the <I>gutter</I>.The gutter is used to display icons at different stages of the development process.For example, when you set a debugger breakpoint (discussed tomorrow), a red dot isplaced in the gutter. When you set a bookmark (discussed in just a bit), an iconrepresenting the bookmark is placed in the gutter.</P><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> If you accidentally click on the gutter when trying to select text or place the cursor, you will find that a breakpoint is set on that line. Click the gutter again to clear the breakpoint. <HR></BLOCKQUOTE><H4>Opening and Saving Files</H4><P>Nothing is very mysterious about opening and saving files in the Code Editor.It should be pointed out, though, that there is a difference between opening a projectand opening a source file. When you choose File|Open Project from the main menu,you are prompted for the name of a project file to open. When you choose File|Openfrom the main menu, you can open an individual Delphi source file or form file. Actually,you can open any type of text file (including file types not listed in the Open dialogbox's Files of Type field). This includes .pas, .rc, .txt, and even C++ source andheader files (.cpp and .h). Both the Open and Open Project menu items have correspondingtoolbar buttons.</P><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> If you open a unit file (.pas) that contains a form, Delphi will open the source file in the Code Editor and will also open the form in the Form Designer.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -