📄 ch09.htm
字号:
removed from the project compile/link process.</P><BLOCKQUOTE> <P><HR><strong>CAUTION:</strong> Be careful when removing units from your projects. You must take care not to remove units that are referenced by other units in the project. If you remove units that are required by your project, a compiler error will result. Before removing a unit, be sure it is not used in your project. If you accidentally remove a needed unit from your project, you can add it back to the project with the Add To Project option as explained in the preceding section. <HR></BLOCKQUOTE><P>The Remove From Project dialog box enables multiple selection, so you can removeseveral units from a project at one time if you want.</P><P><H4>Viewing Units or Forms</H4><P>To view a unit, form, or other file, just double-click the node representing theform or unit you want to view. You can also choose Open from the Project Managercontext menu. The form or unit will be displayed in either the Form Designer or CodeEditor, depending on the type of node you are viewing.</P><P><H3><A NAME="Heading6"></A>Building Projects or Project Groups</H3><P>To build a particular project, you can do one of the following:</P><UL> <LI>Right-click the project node in the Project Manager and choose Build from the context menu. <LI>Choose Project|Build <<I>project name</I>> from the Delphi main menu. The name of this menu item will change based on the name of the active project. <P> <LI>Press Ctrl+F9 on the keyboard to compile the active project.</UL><P>To build an entire project group, choose Project|Build All Projects from the Delphimain menu. All projects in the project group will be built starting with the firstproject in the group (the project at the top of the Project Manager tree) and proceedingdown through the last project in the group.</P><P><H2><A NAME="Heading7"></A>Understanding Project Options</H2><P>Project options are another of those features that are easy to ignore. For one,the defaults are usually good enough when you are just starting out. After all, whohas time to worry about all those compiler/linker options when you are simply strugglingto learn a new programming environment? At some point, though, you will start tobecome more interested in what all those options do, and it's good to have some referencewhen the time comes.</P><P>This section looks at the Project Options dialog box. You can invoke this dialogbox by choosing Project|Options from the main menu. The Project Options dialog boxis a tabbed dialog box with several pages:</P><UL> <LI>Forms <P> <LI>Application <P> <LI>Compiler <P> <LI>Linker <P> <LI>Directories/Conditionals <P> <LI>Version Info <P> <LI>Packages</UL><P>I won't discuss every page of the Project Options dialog box, but you'll takea look at the most important pages so that you can understand more about what eachof these pages does. I'll start you out easy by discussing the Forms and Applicationpages. After that I'll move on to the more complicated pages.</P><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> At the bottom of each page of the Project Options dialog box is a check box labeled Default. If you want the current settings to become the default settings for all new projects created, check the Default box. When you click OK, the current settings become the new default settings. <HR></BLOCKQUOTE><H3><A NAME="Heading8"></A>The Forms Page</H3><P>The Forms page of the Project Options dialog box is where you control how yourapplication handles its forms. You saw this dialog box on Day 4 when you createdthe Picture Viewer program. Figure 9.3 shows the Forms page of the Project Optionsdialog box for the ScratchPad program.</P><P><A HREF="javascript:popUp('28670903.gif')"><B>FIGURE 9.3.</B></A><B> </B><I>TheForms page of the Project Options dialog box.</I></P><P></P><P>At the top of the Forms page is the Main form combo box. This is where you tellDelphi which form to display when the application starts. By default, the first formyou create will be the main form. If you change your project around in such a waythat a different form becomes the main form, you must change this setting so thatthe new form becomes the application's main form.</P><P>In the middle of the dialog box are two list boxes. The list box on the left islabeled Auto-create forms; the one on the right is labeled Available forms. BeforeI talk about how to use these two list boxes, let's take a moment to go over auto-creationof forms.</P><P><I>Auto-creation</I> means that Delphi will construct the form during the applicationstartup process.</P><P>Each time you create a form, Delphi places that form in the auto-create list forthe application. Forms that are auto-created display more quickly than forms thatare not auto-created. The disadvantage to auto-creation of forms is that your applicationwill use more memory than it would if your forms were not auto-created. Another disadvantage,although probably insignificant, is that your application will take slightly longerto load if you are auto-creating a lot of forms.</P><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> The first form in the Auto-create forms list box is always the main form. If you change the main form, the new form selected will move to the top of the Auto-create forms list box. Another way to set the main form is to drag and drop any of the forms in the Auto-create forms list box to the top of the list. <HR></BLOCKQUOTE><P>The nice thing about auto-creation is that displaying an auto-created form iseasy. All you do is call that form's Show or ShowModal function:</P><P><PRE>AboutBox.ShowModal;</PRE><P>If you do not have your forms auto-created by Delphi, you must take the responsibilityof creating the form before you use it:</P><P><PRE>procedure TForm1.Button1Click(Sender: TObject);var About : TAboutBox;begin About := TAboutBox.Create(Self); About.ShowModal; About.Free;end;</PRE><P>This example does not use the Delphi-generated pointer to the About box. It createsa local pointer, displays the form, and then deletes the pointer as soon as the formis no longer needed. As is often the case in Object Pascal programming, there areseveral ways to perform this particular task. Because Delphi always creates a pointerto the form object, you could have written the previous code like this:</P><P><PRE>if not Assigned(AboutBox) then AboutBox := TAboutBox.Create(Self);AboutBox.ShowModal;</PRE><P>This code checks to see whether the form has already been created. If it has not,the object is created, and then the ShowModal method is called. Deciding which methodof form creation you will use is up to you, but I prefer the former because it handleseverything locally.</P><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> Each time you create a form in the Form Designer, Delphi creates a pointer to the form. If you enable Delphi to auto-create a form, you don't have to worry about the pointer being valid. If you choose not to have a form auto-created, the pointer to the form will be nil until you explicitly create the form and initialize the pointer. If you forget and use the pointer before it is initialized, Windows will generate an access-violation error. <HR></BLOCKQUOTE><P>Okay, now turn your attention back to the Project Options dialog box. The Auto-createforms list box contains a list of the forms that will be auto-created. If you donot want a form to be auto-created, drag the form from the Auto-create forms listbox to the Available forms list box. To move several forms at one time, simply selectthe forms you want to move (both list boxes support multiple selection) and dragand drop them all at once. It's that easy.<PRE></PRE><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> You can use the buttons between the two list boxes to move forms from one list box to the other, but it's usually easier to use drag and drop. <HR></BLOCKQUOTE><H3><A NAME="Heading9"></A>The Application Page</H3><P>The Application page of the Project Options dialog box is very simple (see Figure9.4).</P><P><A HREF="javascript:popUp('28670904.gif')"><B>FIGURE 9.4.</B></A><B> </B><I>TheApplication page.</I></P><P>The Title field on this page is used to set the title of the application. Thetitle is the text that will appear on the Windows taskbar when your application isminimized.</P><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> The application's title and the caption of the main form are two separate items. If you want your program's name to show up when you minimize your program, you must be sure that you set the title for the application in the Project Options dialog box. If you do not provide an application title, the name of the project file is used by default. <HR></BLOCKQUOTE><P>The Help file field of the Application page is used to set the help file thatyour application will use. This is the help file that the program will load whenyou press F1 while your application is running. You can use the Browse button tolocate the help file if you can't remember the name or location of the help file.If you do not supply a help file, pressing F1 in your application will have no effect.</P><P>The Icon option enables you to choose an icon for your application. This is theicon that will be displayed in the Windows taskbar when your application runs andwhen it is minimized. In addition, this icon will be displayed on your main form'stitle bar unless you have explicitly set an icon for the main form. To choose anicon, click the Load Icon button and locate the icon file (.ico) using the ApplicationIcon dialog box.</P><P>You use the Target file extension field to specify the filename extension of theproject when the project is built. For example, if you were creating a screen saver,you would change this field to scr so that your screen saver would be created withan extension of .scr rather than .exe. Control Panel applets are another example.These are special programs saved with a .cpl extension. The project filename extensionis automatically set to .exe for executable projects (console applications and GUIapplications) and to .dll for DLLs, so you don't have to provide a value for thisfield for normal projects.</P><P><H3><A NAME="Heading10"></A>The Compiler Page</H3><P>The Compiler page of the Project Options dialog box is where you set the optionsthat the compiler uses to build your project. Figure 9.5 shows this page of the ProjectOptions dialog box.</P><P>The Compiler page is divided into five sections. I'll take each section and examineit so that you can better understand the different options on this page.</P><P><A HREF="javascript:popUp('28670905.gif')"><B>FIGURE 9.5.</B></A><B> </B><I>TheCompiler page of the Project Options dialog box.</I></P><P><I></I><H4>Code Generation</H4><P>The compiler can be configured to perform optimizations on your code. When optimizationsare turned off (the Optimization check box is not selected), the compiler makes noattempts to optimize code in any way. If you turn the Optimization option on, thecompiler will generate the fastest code possible without regard to code size. Inmost cases, you should leave this option on the default setting. Sometimes, however,it is better to turn optimization off while debugging your application. I'll discussoptimization and debugging in more detail on Day 10, "Debugging Your Applications."</P><P>The Aligned Record Fields option is used to control how records are aligned inmemory. When this option is on, records are aligned on 4-byte boundaries. When thisoption is off, records are byte-aligned.</P><P>You might want to turn the Stack Frames option on when debugging. When you arefinished debugging, you can turn off this option to have the compiler generate smallerand faster code, but compile times will be slightly longer with the Stack Framesoption off.</P><P>The Pentium-Safe FDIV option causes the compiler to generate code that detectsa faulty floating-point division instruction.</P><P><H4>Syntax Options and Runtime Errors</H4><P>These two sections affect how the compiler generates code for a project. The Delphihelp for the Compiler page explains what each of these options is for, so I won'trepeat that information here. To display the help page for the compiler options,click the Help button when the Compiler page is displayed or press the F1 key onthe keyboard.</P><P><H4>Debugging</H4>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -