ch04.htm
来自「delphi自学的好教材!特别适合刚刚起步学习delphi的人员!同样对使用者具」· HTM 代码 · 共 1,371 行 · 第 1/5 页
HTM
1,371 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><HTML><HEAD><SCRIPT LANGUAGE="JavaScript"><!--function popUp(pPage) { var fullURL = document.location; var textURL = fullURL.toString(); var URLlen = textURL.length; var lenMinusPage = textURL.lastIndexOf("/"); lenMinusPage += 1; var fullPath = textURL.substring(0,lenMinusPage); popUpWin = window.open('','popWin','resizable=yes,scrollbars=no,width=525,height=394'); figDoc= popUpWin.document; zhtm= '<HTML><HEAD><TITLE>' + pPage + '</TITLE>'; zhtm += '</head>'; zhtm += '<BODY bgcolor="#FFFFFF">'; zhtm += '<IMG SRC="' + fullPath + pPage + '">'; zhtm += '<P><B>' + pPage + '</B>'; zhtm += '</BODY></HTML>'; window.popUpWin.document.write(zhtm); window.popUpWin.document.close(); // Johnny Jackson 4/28/98 }//--> </SCRIPT><link rel="stylesheet" href="/includes/stylesheets/ebooks.css"> <META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1"> <TITLE>Teach Yourself Borland Delphi 4 in 21 Days -- Ch 4 -- The Delphi IDE Explored</TITLE></HEAD><BODY TEXT="#000000" BGCOLOR="#FFFFFF"><CENTER><H1><IMG SRC="../button/sams.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM" BORDER="0"></H1><H1><BR>Teach Yourself Borland Delphi 4 in 21 Days</H1></CENTER><CENTER><P><A HREF="../ch03/ch03.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch05/ch05.htm"><IMGSRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> <HR></CENTER><CENTER><H1>- 4 -</H1></CENTER><CENTER><H1>The Delphi IDE Explored</H1></CENTER><UL> <LI><A HREF="#Heading1">The Delphi IDE</A> <LI><A HREF="#Heading2">Projects in Delphi</A> <UL> <LI><A HREF="#Heading3">Files Used in Delphi Projects</A> <LI><A HREF="#Heading4">Source Code Units</A> </UL> <LI><A HREF="#Heading5">The Delphi Main Menu and Toolbar</A> <LI><A HREF="#Heading6">Using the Component Palette</A> <UL> <LI><A HREF="#Heading7">Placing Multiple Copies of a Component</A> <LI><A HREF="#Heading8">Placing and Centering a Component on the Form</A> <LI><A HREF="#Heading9">The Component Palette Context Menu</A> <LI><A HREF="#Heading10">Navigating the Component Palette</A> </UL> <LI><A HREF="#Heading11">A Multiple-Form Application</A> <UL> <LI><A HREF="#Heading12">Adding Units</A> <LI><A HREF="#Heading13">Compiling, Building, and Linking</A> </UL> <LI><A HREF="#Heading14">Compiling and Building Other Object Pascal Programs</A> <LI><A HREF="#Heading15">More About Delphi Forms</A> <UL> <LI><A HREF="#Heading16">Main Window Forms</A> <LI><A HREF="#Heading17">Dialog Box Forms</A> <LI><A HREF="#Heading18">Secondary Windows Versus Dialog Boxes</A> <LI><A HREF="#Heading19">The Multiple Document Interface Model</A> <LI><A HREF="#Heading20">Key Properties for Forms</A> <LI><A HREF="#Heading21">Form Methods</A> <LI><A HREF="#Heading22">Print</A> <LI><A HREF="#Heading23">Form Events</A> </UL> <LI><A HREF="#Heading24">The Object Inspector</A> <UL> <LI><A HREF="#Heading25">The Component Selector</A> <LI><A HREF="#Heading26">The Properties Page</A> <LI><A HREF="#Heading27">The Events Page</A> </UL> <LI><A HREF="#Heading28">Dockable IDE Windows</A> <UL> <LI><A HREF="#Heading29">Dock Sites</A> <LI><A HREF="#Heading30">Experimenting with Dockable Windows</A> <LI><A HREF="#Heading31">No Docking, Please</A> </UL> <LI><A HREF="#Heading32">An MDI Sample Program</A> <UL> <LI><A HREF="#Heading33">Creating the Main Window Form</A> <LI><A HREF="#Heading34">Writing Code for the File | Open and File | Save As Menu Items</A> <LI><A HREF="#Heading35">Writing Code for the Window Menu</A> <LI><A HREF="#Heading36">Creating the MDI Child Form</A> <LI><A HREF="#Heading37">Creating the About Box</A> <LI><A HREF="#Heading38">Polishing It Up</A> </UL> <LI><A HREF="#Heading39">Summary</A> <LI><A HREF="#Heading40">Workshop</A> <UL> <LI><A HREF="#Heading41">Q&A</A> <LI><A HREF="#Heading42">Quiz</A> <LI><A HREF="#Heading43">Exercises</A> </UL></UL><P><HR SIZE="4"><CENTER><H1></H1></CENTER><P>One of the most difficult aspects of learning how to use a new programming environmentis finding your way around: getting to know the basic menu structure, what all theoptions do, and how the environment works as a whole. If you are new to programmingor new to Object Pascal, this task is complicated by the fact that you have to learna new program (the Delphi IDE) <I>and</I> learn a new language at the same time.It can be overwhelming at times. I'll do my best to make learning the Delphi IDEan enjoyable experience. For the most part, you will learn by example, which is moreinteresting (not to mention more effective).</P><P><H2><A NAME="Heading1"></A>The Delphi IDE</H2><P>So, without further ado, take a look at Figure 4.1 and let's get on with it. Oh,by the way, if you have used Delphi before, you might find this chapter elementary.If that is the case, you might want to at least skim the chapter lightly to catchany tidbits that you did not previously know, particularly features that are newto Delphi 4.</P><P><A HREF="javascript:popUp('2867040.gif')"><B>FIGURE 4.1.</B></A><B> </B><I>TheDelphi IDE.</I></P><P>The Delphi IDE consists of these main parts:</P><UL> <LI>The main menu and toolbars <P> <LI>The Component palette <P> <LI>The Form Designer <P> <LI>The Code Editor <P> <LI>The Object Inspector <P> <LI>The Code Explorer <P> <LI>The Project Manager</UL><P>I can't cover all these in a single chapter, so over the next several chaptersI will show you around the Delphi IDE and examine each of these features in detail.I'll start today by discussing projects and how they are used in writing Delphi applications.After that you'll look at the Delphi toolbar and the Component palette. Then I'llmove to discussing forms in greater detail than I have up to this point.</P><P>Along the way you'll create some sample programs to illustrate various aspectsof Delphi. You'll also take a closer look at the Object Inspector. This will be awarm-up for Day 6, "Working with the Form Designer and the Menu Designer,"when you learn all about the Delphi Form Designer. Later today, I will cover theIDE's dockable windows. Dockable windows make it easy to customize the IDE to suityour tastes and your work style.</P><P>For starters, let's look at the way Delphi views applications and how it has simplifiedthe process of creating programs.</P><P><H2><A NAME="Heading2"></A>Projects in Delphi</H2><P>As you know by now, a lot goes on behind the scenes as you write a Delphi application.In fact, more goes on than I have told you about up to this point. It's not vitalthat you know every detail about what happens behind the scenes as you write a Delphiapplication, but it is a good idea to have a general overview.</P><P><strong>New Term:</strong> A <I>project</I> is a collection of files that work togetherto create a standalone executable file or dynamic link library (DLL).</P><P><strong>New Term:</strong> In addition to a single project, Delphi enables you to createwhat is known as a project group. A <I>project group</I> is a collection of Delphiprojects.</P><P>A project group is used to manage a group of Delphi projects that work togetherto form a complete software product. I'll talk about project groups in more detailon Day 9, "Projects, the Code Editor, and the Code Explorer." For now,you only need to understand that Delphi creates a new, unnamed project group foryou each time you start Delphi (provided you haven't turned on the option to savethe desktop when you close Delphi). Any new projects you create will go into thatproject group. You can save the project group if you like, or you can treat the defaultproject group as temporary.</P><P><H3><A NAME="Heading3"></A>Files Used in Delphi Projects</H3><P>Delphi manages a project through the use of several support files. To illustrate,let's create a simple application to get a look at some of what goes on when Delphibuilds an executable file for your program. Perform the following steps:</P><DL> <DT></DT> <DD><B>1. </B>Before you begin, create a fresh directory on your hard drive. (You can name the directory anything you like.) <P> <DT></DT> <DD><B>2. </B>First choose File | Close All from the main menu so that you are starting from scratch. Now choose File | New Application from the main menu. A blank form is displayed. <P> <DT></DT> <DD><B>3. </B>Choose File | Save All from the main menu. You will be prompted for the name of the unit file. Be sure to navigate to the empty directory you just created. <P> <DT></DT> <DD><B>4. </B>Type the name MyUnit for the unit filename and click the Save Button. <P> <DT></DT> <DD><B>5. </B>Now you are prompted for the project name. Type Test in the File Name field and click Save. <P> <DT></DT> <DD><B>6. </B>Choose Project | Build Test from the main menu. Delphi compiles the program. (It takes just a few seconds.) <P> <DT></DT> <DD><B>7. </B>Choose File | Close All from the main menu. (Yes, this exercise does have a purpose.) <P> <DT></DT> <DD><B>8. </B>Now run Windows Explorer and locate the directory where you saved the project. You will see a number of files. <P></DL><P>You should see a total of about eight files. (The exact number depends on theDelphi IDE options.) First, let me tell you what happens when Delphi builds an application;then I'll explain what each of these files is for.</P><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> Files with extensions that begin with a tilde (~) are backup files. Delphi might create several backup files depending on the number of source files in the project and the project options you have set. Project options are discussed on Day 9. <HR></BLOCKQUOTE><P>When you first create a project, Delphi creates a minimum of four files (assuminga typical Delphi GUI application):</P><UL> <LI>The project source file <P> <LI>The main form unit <P> <LI>The main form resource file <P> <LI>The project resource file</UL><P>The <I>project source file</I> is the file that contains the Delphi startup code.You can view the project source file by choosing Project | View Source from the mainmenu. The <I>main form unit</I> contains the class declaration and definition forthe main form's class. Delphi will create an additional unit file for each new formyou create. The <I>main form resource file</I> and <I>project resource file</I> arebinary files that describe the main form and the application's icon.</P><P>When you tell Delphi to compile the project, it compiles the project source, the
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?