📄 ch02.htm
字号:
<TD WIDTH="84" ALIGN="LEFT"
VALIGN="TOP">DFM</TD>
<TD WIDTH="229" ALIGN="LEFT">Binary file containing form definition. Use<BR>
<TT>CONVERT.EXE</TT> to translate into text.</TD>
<TD ALIGN="LEFT" VALIGN="TOP">Binary</TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD
WIDTH="84" ALIGN="LEFT">MAK</TD>
<TD WIDTH="229" ALIGN="LEFT">The project makefile in text format.</TD>
<TD ALIGN="LEFT">Text</TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="84" ALIGN="LEFT">TDS</TD>
<TD WIDTH="229" ALIGN="LEFT">Turbo
debugger symbols.</TD>
<TD ALIGN="LEFT">Binary</TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="84" ALIGN="LEFT">ILX</TD>
<TD WIDTH="229" ALIGN="LEFT">Incremental linker symbols.</TD>
<TD ALIGN="LEFT">Binary</TD>
</TR>
</TABLE>
<BR>
<BR>
When browsing this table, take special notice of the incremental linker files. These
four files, all of which begin with ILX, are huge. They are the key files needed
to produce BCB's incredibly fast link times. If you turn incremental linking off,
as
explained later in this chapter, these files will disappear. Turning incremental
linking off means that your compilation and link times will be from 5 to 10 times
slower than they are with incremental linking turned on.
<H4><A
NAME="Heading7"></A><FONT COLOR="#000077">The include and lib Directory Paths
Issue</FONT></H4>
<P>There are, confusingly enough, two places where you can designate the paths to
your <TT>include</TT> and <TT>lib</TT> files. One is located in the
Options | Project
| Directories/Conditionals menu choice, and the second is located in the Options
| Environment | Library section. These pages are shown below in Figures 2.1, 2.2,
and 2.3. There is also a Path for Source option in the Options |
Environment | Preferences
page.<BR>
<BR>
<A NAME="Heading8"></A><A HREF="02ebu01.jpg" tppabs="http://pbs.mcp.com/ebooks/0672310228/art/02/02ebu01.jpg">FIGURE 2.1.</A><FONT COLOR="#000077">
</FONT><I>The Options menu leads to the Project dialog where you can set paths for
your project.</I>
<H6></H6>
<P><A
NAME="Heading9"></A><A HREF="02ebu02.jpg" tppabs="http://pbs.mcp.com/ebooks/0672310228/art/02/02ebu02.jpg">FIGURE 2.2.</A><FONT COLOR="#000077">
</FONT><I>The Options menu is also the gateway to the Environment dialog where you
can find the Library page.</I>
<H6></H6>
<P><A NAME="Heading10"></A><A
HREF="02ebu03.jpg" tppabs="http://pbs.mcp.com/ebooks/0672310228/art/02/02ebu03.jpg">FIGURE 2.3.</A><FONT COLOR="#000077">
</FONT><I>The Options | Environment | Preferences page gives you a place to add the
path to modules you include in your projects</I>.</P>
<P>The BCB macro shown in the Path statements
from Figures 2.1 through 2.3 resolves
into the path that points to your current installation of BCB. This kind of information
is stored in the Registry under <TT>HKEY_CURRENT_USER/Software</TT> and <TT>HKEY_LOCAL_MACHINE/Software</TT>.
For instance,
see the <TT>RootDir</TT> entry in <TT>HKEY_LOCAL_MACHINE/Software/C++Builder/1.0</TT>.
To view the Registry, select Run from the Windows Start menu, type in the word <TT>RegEdit</TT>,
and press the Enter key.</P>
<P>As a rule, you make changes
specific to one project in the Options | Project dialog,
and make global changes that you want reflected in all programs in the Options |
Environment dialog. Use the Path for Source to include any directories that contain
utility code that you use
frequently.</P>
<P>As a rule, additions to these various path statements are made automatically when
you add modules to your project through the Project Manager. However, there are times
when I need to go in and explicitly edit one of these
options.</P>
<P>Remember that if you are adding a component to the Component Palette, you have
to add the path to that component in the Options Environment dialog or the Component
Palette will not load. This addition to the Path statement will be made
automatically
if you add a component from inside the IDE. If you add the component from the command
line by recompiling <TT>CMPLIB32.CCL</TT>, you need to update the Library path statement
yourself. If you are using DLLs from inside a component, make
sure the DLL is in
a directory that is on your global DOS/Windows path. For instance, you might consider
putting it in the <TT>Windows</TT> or <TT>Windows/System</TT> directory.
<DL>
<DT></DT>
</DL>
<BLOCKQUOTE>
<P>
<HR>
<FONT
COLOR="#000077"><B>NOTE:</B></FONT><B> </B>The question of whether to call
a C module used in a BCB program a unit or a module is something of an open matter
in BCB. My inclination is to call it a module, because that is traditional C usage,
but
BCB seems to refer to them as units. To be utterly frank, this is the kind of
issue that doesn't really grip me all that deeply. In particular, I'm sure you will
have no trouble understanding me regardless of which term I use. As a result, you
will
hear me referring to C modules as either modules or units, depending more on
whim than on any clearly defined practice.
<HR>
</BLOCKQUOTE>
<H3><A NAME="Heading12"></A><FONT COLOR="#000077">Working in the IDE</FONT></H3>
<P>Here are some tips for
working inside the IDE. I'll make this section brief, because
I don't want to waste time on issues like this in a book that is clearly aimed at
experienced programmers. However, this is a new environment, so it might help to
share a few tips.</P>
<P>Whatever you do, be sure that you understand that this tool is meant to be used
from inside its IDE. This is not a command-line environment!
<DL>
<DT></DT>
</DL>
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>I'm sure
that most programmers who
investigate the matter will see that the command-line approach makes no sense with
BCB. If that sentence strikes a sour note with you, all I ask is that you don't develop
contempt prior to investigation. In my opinion,
this IDE has something so powerful
to offer that it finally makes command-line programming obsolete. With BC5, and even
with MSVC, I usually worked from the command line. I was one of the last of the hardcore
C++ command-line junkies. With BCB,
however, I have changed my ways. I'm totally
sold on this environment, and would never consider going back to the command line
except for a few rare situations.
<HR>
</BLOCKQUOTE>
<H4><A NAME="Heading14"></A><FONT COLOR="#000077">Tips on
Manipulating Controls</FONT></H4>
<P>Here are a few tips for using the visual tools. If you are new to the environment,
you should boot up BCB and follow along when reading these time-saving tips.</P>
<P>When dropping controls on a form, do the
following:
<UL>
<LI>Use the Control key plus the arrow keys to move the location of a component one
pixel at a time. In particular, drop a component such as a button on a form. Select
it with the mouse. Hold down the Control key and press the left
arrow key.
<P>
<LI>Repeat the previous steps, only this time use Shift plus the arrow keys to resize
a component one pixel at a time.
<P>
<LI>Hold down the Shift key when selecting a component from the Component Palette
if you want to drop
multiple copies of it on a form without having to go back to
the palette. Click the "arrow" icon at the far left of the Component Palette
to break out of this process.
<P>
<LI>Become familiar with the Align and Size options from the Edit
menu. Quickly drop
down five buttons on a form, each one below the last, without taking the time to
carefully align their right and left sides. Hold down the Shift key, then select
the five buttons with the mouse by clicking on each one. Now use
the Align dialog
from the Edit menu to align the tops or sides of all the selected controls.
<P>
<LI>A second technique for selecting a large group of components is to click on the
main form and hold down the left mouse button while dragging over
several components.
When you let up the mouse, you will find the components are selected. If the components
you want to select are resting on top of another control such as a panel, then you
will need to hold the control button down before and
during the process of dragging
the mouse.
<P>
<LI>When designing a form, make it as large as you want. Then, when you have everything
in place, use the Scale option from the Edit menu to make your form as small as you
want, while still keeping
each item on the form in proportion.
<P>
<LI>Right-click a component, as shown in Figure 2.4, to bring up a menu that lets
you change the size, alignment, tab order, scaling, or creation order.
</UL>
<P><BR>
<A NAME="Heading15"></A><A
HREF="02ebu04.jpg" tppabs="http://pbs.mcp.com/ebooks/0672310228/art/02/02ebu04.jpg">FIGURE 2.4.</A><FONT COLOR="#000077">
</FONT><I>Right-clicking a <TT>TTable</TT> object to bring up a list of custom options.</I>
<H4><A NAME="Heading16"></A><FONT COLOR="#000077">Making the Most of the IDE</FONT></H4>
<P>Here are some tips on using the IDE:
<UL>
<LI>Right-click almost anything in the IDE to bring up a menu to configure the component
or tool you are currently using. For instance, right-click the colorful toolbar at
the top left of the
environment. Select Properties from the popup menu to bring up
the Toolbar editor. Now drag a colorful button from the toolbar onto the Toolbar
editor and grab another button from the ToolBar editor and drag it back onto the
toolbar. I sometimes
delete the Trace, Trace Into, and Pause buttons from the extreme
right of the toolbar and replace them with Copy, Cut, and Paste buttons or with compiler
buttons such as Make, Build All, and Compile Unit.
<P>
<LI>Notice that you can view the
Project Source and Project Makefile from the View
menu. The project source contains the <TT>WinMain()</TT> or <TT>main()</TT> block
for your code. You rarely will need to edit this code. Its contents are usually configurable
from the Options |
Project menu. For instance, you can change the code in the Project
Source from Forms page of the Options | Project menu.
<P>
<LI>Check out the Project Manager, which is also available from the View menu.
<P>
<LI>You can lock the controls on a
form by selecting the Lock Controls option from
the Edit menu. If you have spent some time working on a form and want to be sure
that it does not accidentally get changed, select Lock Controls, and it will not
be possible to move the controls on
that form, or any other, until you deselect this
option.
<P>
<LI>If you want to set the text on the editor page to read only, right-click the
editor page and select Read Only.
<P>
<LI>Watch out for the <TT>AutoScroll</TT> property of a form.
This is set to <TT>true</TT>
by default, but it can bite back if you leave it set to <TT>true</TT> and then move
your form to a different resolution. For instance, if you move from 640x480 to 800x600,
you generally should not have
<TT>AutoScroll</TT> set to <TT>true</TT>, especially
if your form is populated with a large number of controls.
<P>
<LI>Use the <TT>Position</TT> property of a form to decide whether the form should
first appear in the screen center, at the place
where you positioned it at design
time, or at a default location defined by Windows.
<P>
<LI>Use the <TT>WindowState</TT> property of a form to decide if the form should
first be shown minimized, maximized, or at normal size.
<P>
<LI>Before
releasing a project to the public, check out its appearance in at least
three different resolutions and make sure at least one of them toggles the font from
Small Fonts to Big Fonts, or vice versa. (You can change Windows' resolution by
right-clicking
the desktop, selecting Properties, and going to the settings page. Make sure you
change between Big Fonts and Small Fonts during your testing!)
</UL>
<H4><A NAME="Heading17"></A><FONT COLOR="#000077">Project Options</FONT></H4>
<P>Other than the path-related issues covered in the last section, there are only
a few options that you need to know about when programming BCB. The rest of the setup-related
issues are handled for you automatically by the environment.</P>
<P>All the
options you choose in the Project and Environment dialogs are written
to the Registry. If you want to write custom programs that change these settings,
you can learn how to proceed by reading the sections on the Registry in Chapter 13,
"Flat-File, Real-World Databases."</P>
<P>The Options | Project menu has six pages in it:
<BLOCKQUOTE>
<P><B>Forms</B>: This page is discussed in depth later in the chapter when I discuss
the Project Source file for the ShapeDem program
in the section called "Creating
Forms." The core functionality on this page addresses the question of which
unit will be the main module for your application--that is, which will come up first
when you start the program. A secondary issue
addressed in this page is whether a
form will have memory allocated for it automatically at startup, or whether you want
to create it explicitly at some point during your application's runtime. Forms listed
in the left-hand list box shown on this
form are created automatically; those on
the right-hand list box must be created explicitly by the developer. The following
code will create a form, show it to the user, and delete it:</P>
<PRE><FONT COLOR="#0066FF">Form2 = new TForm2(this);
Form2->ShowModal();
delete Form2;
</FONT></PRE>
<P>This code would not work unless the header for Form2 was included in the module
that wanted to call the code quoted here:</P>
<PRE><FONT COLOR="#0066FF">#include "unit2.h"
</FONT></PRE>
<P><B>Application</B>: This is where you can set up the icon or help file for your
project. This is an intuitive process; click Help in the dialog if you have questions.</P>
<P>C++: This is where you can set the Debug and Release
compiler options. You can
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -