📄 ch02.htm
字号:
also do a small amount of fine-tuning here, but this book hardly ever steps beyond
recommending that you use the Debug option in development and the Release version
when you ship. I almost never have occasion to do more
than choose the simple binary
Debug or Release option, except for occasionally toggling the precompiled headers
option.</P>
<P><B>Pascal</B>: Here is where Pascal aficionados can fine-tune their code. I would
recommend leaving all these options
untouched unless you have a specific reason to
change them. If you want to get involved in this page, the first level of advice
is to turn Range and Stack checking on only during debug cycles, and to turn Optimizations
on only when you ship.</P>
<P><B>Linker</B>: This is where you can decide to produce a Windows or console application,
an EXE, or a DLL. This is also the place where you can toggle the incremental linker
on and off. In development, you probably want the incremental linker on
to speed
compilation; when you ship, you should test the size of your executables when it
is off and when it is on, and ship the smallest version.<BR>
<B><BR>
Directories / Conditionals:</B> The key features of this page were covered earlier
in
this chapter. Note that this is also where you can define conditionals. The whole
subject of unit aliases is an Object Pascal-specific issue that enables you to create
an alias for the name of a unit. For instance, the 16-bit version of Delphi kept
all the Windows API calls in a unit called <TT>WinProcs.pas</TT>, and all the Windows
types in a unit called <TT>WinTypes.pas</TT>. When the big segment sizes of 32-bit
Windows became available, the two units were consolidated into one called
<TT>Windows.pas</TT>.
To remove the burden of having to change the uses (<TT>#include</TT>) statements
in a Pascal file, the developers enabled you to create aliases. The most common alias
told the compiler to use <TT>Windows.pas</TT> whenever it
saw a request to include
the <TT>WinTypes</TT> or <TT>WinProcs</TT> units.<BR>
As you can see, I don't put a lot of weight on fine-tuning the settings for your
project. If you flip through these pages and see the small number of options available,
you can see that the developers were not very concerned about this issue either.
One of the major goals of BCB is to make C++ once again a mainstream language. The
programming world used to be much simpler than it is today. Now we are all expected
to know about OLE, MAPI, the Internet, multimedia, or other cutting-edge technologies.
I invest my time in learning these valuable new technologies, and ask little more
of my compiler than that it link quickly and easily and automatically produce
small,
tight code.
</BLOCKQUOTE>
<H4><A NAME="Heading18"></A><FONT COLOR="#000077">Environment Options</FONT></H4>
<P>There are six pages in the Options | Environment menu choice. I play with many
of these options all the time because they do
nothing more than tweak the appearance
or feel of the IDE. You aren't going to accidentally mess up the link process in
your program or add 500KB to the size of an executable by tweaking one of these options.
Feel free to set them as you please.
Following is a list of the options I often play
with during development.</P>
<P>There are some choices that are listed in both the Environment Options pages and
the Project Options pages. If you make a change in the Project pages, you are changing
an
option for just that one project, while if you make the change in the Environment
page, you are changing things globally for the entire environment. Local options
always override global options. <BR>
<BR>
<B>Preferences:</B> In the preferences page I
always set Show Compiler Progress to
true so that I can tell how far along I am in the compile cycle. I set AutoSave to
true for Desktop files so that the environment will remember which project I was
working on and which files I had open in the IDE.
I also frequently tweak Break On
Exception, depending on whether or not I want to catch problems in my code (turn
it on) or just test to see if exceptions are popping up as expected at runtime (turn
it off). This is also where you can turn integrated
debugging on and off and change
the path, as described above in the section on setting the project path.</P>
<P><B>Library</B>: This is where you can set the path for <TT>include</TT> and <TT>lib</TT>
files, as described previously. You can also
globally decide for all projects whether
or not to use the incremental linker. If you are adding components to the Component
Palette, you should set Save Library source code to true so that you can build the
Component Palette from the command line to
save time or to repair a damaged Component
library.</P>
<P><B>Editor</B>: I discuss this page in a later section called "Feeling at
Home in the IDE." It is here you can customize the behavior of the editor. All
the major third-party editors
(CodeWright, SlickEdit, MultiEdit) have some customizations
for BCB, but none of them can get into the environment to the degree to which you,
I, and they would like. Hopefully, improvements will come in this area in later releases.</P>
<P><B>Display</B>: I discuss this page in a later section called "Feeling at
Home in the IDE." It is here you can choose the keystroke emulation and font
for the editor.</P>
<P><B>Colors</B>: I discuss this page in a later section called
"Feeling at
Home in the IDE." It is here you can customize the colors of the editor. It
particular, it enables you to switch between different color schemes or customize
the colors for each element in the language, such as string,
identifiers, integers,
and so on. Like all the settings mentioned in these pages, the results of your decisions
are written to the Registry. The Address2 program from Chapter 13 shows how you could
write custom programs that tweak the Registry. For
instance, you could write a program
that automatically switched between four or five additional color schemes.<BR>
<B><BR>
Palette</B>: If you want to change the order in which components appear in the Component
Palette, this is the place to make your
changes. You can also reach this page by
right-clicking the Component Palette and choosing Properties. It is pretty hard to
do any serious damage to the environment using this page, but if you feel you need
help, just press the Help button on the
dialog itself.<BR>
As you can see, most of the options on these pages address only aesthetic or habit-based
preferences regarding how the IDE works. From a development point of view, the key
issues involve incremental linking, paths, and saving the
source for the Component
Palette. Make sure you understand those important issues before moving on to the
next topic of discussion.
<H4><A NAME="Heading19"></A><FONT COLOR="#000077">Feeling at Home in the IDE</FONT></H4>
<P>To help make the IDE
comfortable, you might go to the Options | Environment |
Editor page, shown in Figure 2.5.<BR>
<BR>
<A NAME="Heading20"></A><A HREF="02ebu05.jpg" tppabs="http://pbs.mcp.com/ebooks/0672310228/art/02/02ebu05.jpg">FIGURE 2.5.</A><FONT COLOR="#000077">
</FONT><I>The Options menu gives you access to the
Environments dialog where you
find the Editor page.</I></P>
<P>From the Editor page you can make the following changes:
<UL>
<LI>Turn the Use tab character option on or off, depending on your liking. (I prefer
to turn it off, so I always know
exactly what my code will look like regardless of
the editor or tab settings I happen to use.)
<P>
<LI>Decide what tab stops you want to use. I set mine to 3 and 5.
<P>
<LI>Choose the Editor speed setting you want. You can choose between the
Default
keymapping, IDE Classic, Brief, or Epsilon emulations.
<P>
<LI>Go to the Colors page and set the colors you want to use in the editor.
<P>
<LI>Consider setting Undo after save to true so that you can keep a buffer of changes
you make,
even after you save.
<P>
<LI>There are third-party tools such as SlickEdit, MultiEdit, and CodeWright that
have some degree of integration with C++Builder. However, none of these products
is able to work as closely with the IDE as one would like,
due to limitations in
the current Tools API for BCB.
</UL>
<H4><A NAME="Heading21"></A><FONT COLOR="#000077">Converting Forms to Text and Back</FONT></H4>
<P>Everything you can do in BCB through the visual tools you can also do in code.
The visual
tools are just a means of expediting the programming process. They do
not supplant code, they complement it. This is what the Borland marketing department
means when they talk about "two way tools." The are two different ways
to approach
some parts of a BCB project: in code or by using the RAD tools.</P>
<P>If you right-click a form, you can select the View as Text menu item to convert
a form to text. To convert back, just right-click the text version of the form.</P>
<P>BCB also
ships with a command-line utility called Convert that will convert DFM
files to text, or text to DFM files. At the command line type either</P>
<PRE><FONT COLOR="#0066FF">convert MyForm.dfm
</FONT></PRE>
<P>or</P>
<PRE><FONT COLOR="#0066FF">convert
MyForm.txt
</FONT></PRE>
<P>The first example converts a binary form to a text form with the extension TXT,
and the second example reverses the process.</P>
<P>If you have 4DOS on your system, you can use the following command to convert
all the DFM
files in a branch of subdirectories from DFM to text files:</P>
<PRE><FONT COLOR="#0066FF">global /I convert *.dfm
</FONT></PRE>
<P>This command will iterate through all the subdirectories below your current position
and convert all the files in
those directories to text. If you are concerned about
archiving files, this is a good way to proceed. In particular, a text file is a much
more robust storage medium than a binary file. If you lose one byte of a binary file,
it may become worthless.
Losing one byte from a text file rarely causes any serious
mischief.</P>
<P>If you have one form and want to paste all or part of it into a second form, you
can select multiple objects from the first form, choose Edit | Copy, focus the second
form,
and then paste the selections from the first form into it. If you want, you
can have an intermediate step where you paste the items from the first form into
a text editor such as Notepad, edit them, and then paste them onto a form.
<DL>
<DT></DT>
</DL>
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>If you are a Delphi programmer and
want to port a form from Delphi to BCB, you might consider using the technique outlined
in the last paragraph as a way to proceed. Of
course, you can compile your Delphi
forms directly in BCB, but if you want to port them, just cutting and pasting to
the clipboard is a good way to proceed.
<HR>
</BLOCKQUOTE>
<P>Here is a what a BCB button looks like in text form:</P>
<PRE><FONT COLOR="#0066FF">object Button1: TButton
Left = 96
Top = 16
Width = 75
Height = 25
Caption = `Button1'
TabOrder = 0
end
</FONT></PRE>
<P>To get this code, I Alt+Tabbed out of my word processor over to BCB, selected
a
button on a form, and chose Edit | Copy from the menu. I then Alt+Tabbed back to
my word processor, and chose Edit | Paste. During the process the Windows button
was automatically converted to text.</P>
<P>Here is a second version of the button code
that has been slightly modified:</P>
<PRE><FONT COLOR="#0066FF">object MyButton: TButton
Left = 1
Top = 16
Width = 75
Height = 25
Caption = `My Button'
TabOrder = 0
end
</FONT></PRE>
<P>As you can see, I have changed the name of
the button from <TT>Button1</TT> to
<TT>MyButton</TT>, and I have changed the <TT>Caption</TT> and <TT>Left</TT> properties.
Now I can select this text in my word processor, Alt+Tab over to BCB, select and
form, and choose Edit | Paste to paste it
back into the form. However, this time
it has a new name, a new location, and new caption.</P>
<P>This is what is meant by a two-way tool. I can edit the form using the visual
tools, or I can edit it in a word processor. It works in two different
ways, depending
on my current needs.
<DL>
<DT></DT>
</DL>
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>When working with forms, remember
that the currently selected component will be the target for a Paste operation.
For
instance, if I have selected a <TT>TButton</TT> object, and I chose Paste, BCB will
attempt to make the control currently in the clipboard into a child of the button.
In most cases, this is not what I want. Instead, I should first select a form
or
a panel, and then paste the controls onto that object. You also want to make sure
the object you are pasting into is big enough to receive the control or controls
you are about to dump from the Clipboard.
<HR>
</BLOCKQUOTE>
<P>You have now
made it through the first section of this chapter. In the next section
I am going to switch my approach from a "hot tips" format to a more discursive
style. If you want more information of the type you have seen so far in this chapter,
you
should look in the online help or pick up a book aimed at introductory BCB programming
issues. Everyone has to know the kind of information I have been ladling out in the
last few pages, and indeed it is vital information, but it is not the subject
matter
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -