📄 ch08.htm
字号:
</BLOCKQUOTE><P>An object can be moved from one page to another by simply dragging the objectfrom the Objects list box to the Pages list box. Drop the object on the page on whichyou want the object to be located, and the object is moved.</P><P><H4>Managing Pages</H4><P>The previous section deals with editing, deleting, and moving individual objects.You can also add, delete, or remove Object Repository pages through the Object Repositoryconfiguration dialog box. Before you can delete a page, you must first delete allthe objects on the page. After a page is empty, you can remove the page by clickingon the page name in the Pages list box and then clicking the Delete Page button.After checking to be sure the page is empty, Delphi deletes the page from the ObjectRepository.</P><P>A new page can be added by clicking the Add Page button. A dialog box pops upasking for the name of the new page. Just supply a new page name and when you clickOK, the new page appears in the Pages list box. Renaming a page works essentiallythe same way. When you select a page and click the Rename Page button, a dialog boxappears prompting you for the new page name.</P><P>The order in which the pages appear in the Object Repository can be changed. Tochange a page's position in the page order, click the page to highlight it and thenclick the up or down arrow button underneath the Pages list box to move the pageup or down in the list. You can also drag a page to its new location if you want.</P><P><H4>Setting Default Forms and Projects</H4><P>The Object Repository configuration dialog box enables you to set three defaultobjects:</P><UL> <LI>The default form that is used when you choose File | New Form from the main menu. <P> <LI>The default form that is used as the main form when you choose File | New Application from the main menu.<BR> <BR> <LI>The default project that is used when you choose File | New Application from the main menu.</UL><P>You will notice that, depending on the object you select, one or two check boxesappear beneath the Objects list box. If you select a form, the New Form and MainForm check boxes appear. If you select a project, the New Project check box appears.</P><P><P>Making a form or project the default is easy. Let's say you create a main formthat you want to be the default main form when a new application is created. Selectthe form from the Objects list box and click the Main Form check box at the bottomof the screen. When you click OK, that form will now be the default. Similarly, ifyou have a project that you want to be the default project, first locate it in theObject Repository configuration dialog box, click on it, and then check the New Projectcheck box. From that point on, when you choose File | New Application from the mainmenu, the project you set as the default will appear.</P><PRE></PRE><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> If you aren't careful, you can accidentally select a form as the default form for a new application. If this happens, be sure you check each form in the Object Repository configuration dialog box. One form will have the Main Form check box checked. Clear the check box and all will be back to normal. This also applies to the default project. Check the Projects page for any items that have the New Project check box checked. <HR></BLOCKQUOTE><P><H2><A NAME="Heading8"></A>Building Forms and Applications with the Wizards</H2><P>Delphi has two built-in wizards designed to guide you through the applicationcreation process. The Dialog Wizard aids you in creating dialog boxes, and the ApplicationWizard helps you create the basic layout of an application. These wizards are discussedin the following sections.</P><P><H3><A NAME="Heading9"></A>Using the Dialog Wizard</H3><P>Truthfully, there isn't very much for a dialog box wizard to do because dialogboxes of any real value will need to be customized with the Form Designer. The DialogWizard is started from the Object Repository. First, choose File | New from the mainmenu to display the Object Repository. Next, switch to the Dialogs page and thendouble-click the Dialog Wizard icon. The Dialog Wizard is displayed as shown in Figure8.5.</P><P><A HREF="javascript:popUp('28670805.gif')"><B>FIGURE 8.5.</B></A><B> </B><I>TheDialog Wizard.</I></P><P>You can choose to create a single-page dialog box or a tabbed (multipage) dialogbox. The icon on the left side of the dialog box shows you what the dialog box lookslike at each step. If you choose to create a single-page dialog box, when you clickthe Next button, you will see the next page of the Dialog Wizard (see Figure 8.6).</P><P><A HREF="javascript:popUp('28670806.gif')"><B>FIGURE 8.6.</B></A><B> </B><I>Thesecond page of the Dialog Wizard.</I></P><P>This page enables you to choose whether you want buttons on the dialog box and,if so, whether you want them on the right side or the bottom of the dialog box. Thisis the last page of the Dialog Wizard when creating a single-page dialog box. Afterchoosing the button layout you want, click the Finish button to have Delphi createthe dialog box for you.</P><P>The new dialog box is displayed on the Form Designer complete with the featuresyou chose through the wizard. It also has its BorderStyle property set to bsDialog,which is customary for forms used as dialog boxes. After the Dialog Wizard has createdthe basic dialog box, you can go to work with the Form Designer to add functionalityto the dialog box.</P><P>If you choose to create a tabbed dialog box, the second page of the dialog boxlooks like the one shown in Figure 8.7. (Figure 8.7 shows the dialog box after pagenames have been added.)</P><P>This page has a multiline edit control in which you can enter the names of theindividual tabs you want to see on the dialog box. Enter the text for each tab ona separate line, as illustrated in Figure 8.7. When you click the Next button, youwill see the last page of the Dialog Wizard as you saw in Figure 8.6. Choose thelocation of the buttons, if any, and click the Finish button to have Delphi createthe tabbed dialog box.</P><P><A HREF="javascript:popUp('28670807.gif')"><B>FIGURE 8.7.</B></A><B> </B><I>TheDialog Wizard creating a tabbed dialog box.</I></P><BLOCKQUOTE> <P><HR><BR> <strong>NOTE:</strong> The Dialog Wizard is most useful when creating tabbed dialog boxes. When creating single-page dialog boxes, it is easier to choose one of the pre-defined dialog boxes from the Object Repository rather than going through the Dialog Wizard. <HR></BLOCKQUOTE><H3></H3><H3><A NAME="Heading10"></A>Creating Applications with the Application Wizard</H3><P>The Application Wizard is a useful tool that can help you quickly set up the shellof an application. To create a new application using the Application Wizard, chooseFile | New from the main menu. When the Object Repository appears, click the Projectstab and then double-click the Application Wizard icon.</P><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> The New Application item on the main menu creates a new application based on the current default project setting. It doesn't start the Application Wizard as you might expect. <HR></BLOCKQUOTE><P>Let's walk through the Application Wizard one page at a time.</P><P><H4>Page One: Selecting the Menus</H4><P>When you start the Application Wizard, the first page is displayed as shown inFigure 8.8.</P><P>This page enables you to select the items you want on your application's mainmenu. You can choose to add a File menu, an Edit menu, a Window menu, and a Helpmenu. Place a check in the box for each menu item you want to appear on your menubar.</P><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> The Window menu is usually reserved for MDI applications. You probably won't put a Window menu on your SDI application's menu bar unless you have a specialty application that requires it. <HR></BLOCKQUOTE><P><A HREF="javascript:popUp('28670808.gif')"><B>FIGURE 8.8.</B></A><B> </B><I>Pageone of the Application Wizard.</I></P><BLOCKQUOTE> <P><HR><BR> <strong>NOTE:</strong> The menus added by the Application Wizard are a reasonable representation of the menu items that are most commonly used in Windows applications. Remember that the Application Wizard is intended to give you a head start in creating your application. It is up to you to take the basic structure and modify it to make a working application. <HR></BLOCKQUOTE><P>After you have chosen the menus you want for your application, click the Nextbutton to move to the next page.</P><P><H4>Page Two: Setting the File Dialog Filters</H4><P>If you chose to add a File menu to your application, the next page displayed willlook like the one shown in Figure 8.9.</P><P><A HREF="javascript:popUp('28670809.gif')"><B>FIGURE 8.9.</B></A> <I>Setting filtersfor the file dialog boxes.</I></P><P>This page enables you to set the filters that your application's File Open andFile Save dialog boxes will use. (Figure 8.9 shows the dialog box after the filtershave been added.) Click the Add button to add a new filter. A dialog box is displayedasking for the description and the filter. Enter the filters exactly as you do whensetting the Filter property for the common file dialog box components. Enter thetextual description and then the actual file mask (*.bmp, for example). The Edit,Delete, Up, and Down buttons can be used as necessary to change, delete, or movethe filter in the list.</P><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> Pages two and three will be displayed only if you previously selected menus on page one of the Application Wizard. More specifically, page two will be displayed only if you selected a File menu on page one. <HR></BLOCKQUOTE><P><H4>Page Three: Setting Up the Speedbar</H4><P>Page three of the Application Wizard aids you in setting up a speedbar (also calleda toolbar) for your application. This is possibly the most useful feature of theApplication Wizard (not that the other features aren't useful). You can quickly layout your speedbar through this page. Figure 8.10 shows the third page of the ApplicationWizard after a speedbar has been created.</P><P><A HREF="javascript:popUp('28670810.gif')"><B>FIGURE 8.10.</B></A><B> </B><I>Settingup the speedbar.</I></P><P>The list box on the left side of the page, labeled Menus, shows the four menusfor which you can add buttons. When you choose one of the menus, the available buttonsfor that menu are displayed in the list box to the right of the Menus list box (labeledAvailable Commands). To add a speedbar button, click the button in the AvailableCommands list box and then click the Insert button. The button will be added to thesample speedbar at the top of the page.</P><P>The Space button can be used to add a separator to the speedbar. Adding separatorsvisually distinguishes groups of buttons. Continue to add buttons and spaces as neededuntil the speedbar is complete. If you decide to remove a button, just click it inthe sample speedbar and then click the Remove button.</P><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> If you elected not to add a particular menu to your application, no buttons will be shown for that menu group. For example, if you did not add a Window menu, the Available Commands list box will be empty when you click on the Window item in the Menus list box. <HR></P> <P><HR><BR> <strong>TIP:</strong> Some specialty applications have a speedbar but don't have a menu. To create a speedbar with the Application Wizard, you must first have created a menu. To work around this, tell the Application Wizard that you want a menu and then build the speedbar. After the application has been generated, you can delete the MainMenu component from the application to remove the menu. <HR></BLOCKQUOTE><H4><BR>Page Four: Setting the Final Options</H4><P>The fourth and last page of the Application Wizard enables you to set the programname, the path where the project should be stored on disk, and a few final options.Figure 8.11 shows the last page of the Application Wizard.</P><P><A HREF="javascript:popUp('28670811.gif')"><B>FIGURE 8.11.</B></A><B> </B><I>Thefinal Application Wizard settings.</I></P><P>The first field on this page is where you specify the name of the application.This is not the name as it appears on the Project Options dialog box, but the filenamethat Delphi will use to save the project. You still need to set the application namein the Project Options dialog box. The second field is used to specify the directoryin which the project should be saved. If you don't know the exact path, click theBrowse button to the right of this field and choose the path from the Select Directorydialog box.</P><BLOCKQUOTE> <P><HR><STRONG>NOTE:</STRONG> You can use the Select Directory dialog box to create a directory as well as to select a directory. Click the Browse button to display the Select Directory dialog box. Enter the path for the directory you want to create and then click OK or press Enter. Delphi will prompt you to create the new directory if the directory you entered doesn't exist. <HR></BLOCKQUOTE><P>The bottom half of the final page gives you three additional options. If you arecreating an MDI application, click the check box marked Create MDI Application. (MDIapplications were discussed on Day 4, "The Delphi IDE Explored.") The remainingtwo check boxes enable you to implement a status bar and hint text for your components.</P><P>When you are sure you have made all the choices for your new application, clickthe Next button. Delphi creates the application based on the options you specified.Delphi writes as much code as possible for the application. This doesn't amount toa lot of code, but some of the basic code is already written for you. For example,if you chose a File menu, the FileOpenClick handler has been written and looks likethis:</P><P><PRE>procedure TMainForm.FileOpen(Sender: TObject);begin if OpenDialog.Execute then begin { Add code to open OpenDialog.FileName } end;end;</PRE><P>The code to execute the File Open dialog box is in place; you only have to writethe code that actually deals with the returned filename.</P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -