⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch14.htm

📁 好书《C++ Builder高级编程技术》
💻 HTM
📖 第 1 页 / 共 5 页
字号:
programmers
who are new to this kind of programming.</P>
<P>Several secondary indexes are used in this program, as shown in Table 14.7 through
Table 14.11. Most of these indexes are the result of the foreign keys on the <TT>NameCode</TT>
fields of 
<TT>kdAdds</TT>, <TT>kdPhone</TT>, <TT>kdEMail</TT>, and <TT>kdMemo</TT>.
However, indexes are also set up on the <TT>Company</TT>, <TT>FirstName</TT>, and
<TT>LastName</TT> fields of the <TT>kdNames</TT> table. Note that <TT>idxLastName</TT>
consists 
of both the last name and first name of each entry in the <TT>kdNames</TT>
table. This convention is helpful when sorting lists wherein you have more than one
entry with a particular last name. For instance, if you have two people with the
last name 
of Jones, creating a key on the last and first names will ensure that Able
Jones is listed before Betty Jones. If you further study the tables shown here, you
will see that the <TT>kdPhone</TT> and <TT>kdMemo</TT> tables also have indexes on
their 
description fields. <BR>
<BR>
<B>Table 14.7. The indexes on the kdNames table. </B>
<TABLE BORDER="1">
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="102" ALIGN="LEFT"><B>Table</B></TD>
		<TD WIDTH="137" ALIGN="LEFT"><B>Index fields</B></TD>
	</TR>
	<TR 
ALIGN="LEFT" rowspan="1">
		<TD WIDTH="102" ALIGN="LEFT"><TT>idxCompany</TT></TD>
		<TD WIDTH="137" ALIGN="LEFT"><TT>Company</TT></TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="102" ALIGN="LEFT"><TT>idxFirstName</TT></TD>
		<TD WIDTH="137" 
ALIGN="LEFT"><TT>FirstName</TT></TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="102" ALIGN="LEFT"><TT>idxLastName</TT></TD>
		<TD WIDTH="137" ALIGN="LEFT"><TT>LastName</TT>, <TT>FirstName</TT></TD>
	</TR>
</TABLE>
<BR>
<BR>
<B>Table 14.8. The 
index on the kdAdds table. </B>
<TABLE BORDER="0">
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="109" ALIGN="LEFT"><B>Table</B></TD>
		<TD WIDTH="131" ALIGN="LEFT"><B>Index fields</B></TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="109" 
ALIGN="LEFT"><TT>NameCode</TT></TD>
		<TD WIDTH="131" ALIGN="LEFT"><TT>NameCode</TT></TD>
	</TR>
</TABLE>
<BR>
<BR>
<B>Table 14.9. The indexes on the kdPhone table. </B>
<TABLE BORDER="1">
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="121" 
ALIGN="LEFT"><B>Index</B></TD>
		<TD WIDTH="125" ALIGN="LEFT"><B>Index fields</B></TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="121" ALIGN="LEFT"><TT>idxDescription</TT></TD>
		<TD WIDTH="125" ALIGN="LEFT"><TT>Description</TT></TD>
	</TR>
	
<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="121" ALIGN="LEFT"><TT>NameCode</TT></TD>
		<TD WIDTH="125" ALIGN="LEFT"><TT>NameCode</TT></TD>
	</TR>
</TABLE>
<BR>
<BR>
<B>Table 14.10. The index on the kdEmail table. </B>
<TABLE BORDER="1">
	<TR 
ALIGN="LEFT" rowspan="1">
		<TD WIDTH="127" ALIGN="LEFT"><B>Index</B></TD>
		<TD WIDTH="118" ALIGN="LEFT"><B>Index fields</B></TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="127" ALIGN="LEFT"><TT>NameCode</TT></TD>
		<TD WIDTH="118" 
ALIGN="LEFT"><TT>NameCode</TT></TD>
	</TR>
</TABLE>
<BR>
<BR>
<B>Table 14.11. The indexes on the kdMemo table. </B>
<TABLE BORDER="1">
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="135" ALIGN="LEFT"><B>Index</B></TD>
		<TD WIDTH="113" 
ALIGN="LEFT"><B>Index fields</B></TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="135" ALIGN="LEFT"><TT>NameCode</TT></TD>
		<TD WIDTH="113" ALIGN="LEFT"><TT>NameCode</TT></TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="135" 
ALIGN="LEFT"><TT>idxDescription</TT></TD>
		<TD WIDTH="113" ALIGN="LEFT"><TT>Description</TT></TD>
	</TR>
</TABLE>
<BR>
<BR>
You now know all the core facts about the kdAdds program. After you have laid out
the tables as shown here, all the really 
heavy work in constructing the program is
completed. You still have considerable work to do in creating a front end for the
program, but the core work for the project is done after you have created the tables
and defined the ways in which they 
interrelate.
<H3><A NAME="Heading9"></A><FONT COLOR="#000077">The Code for kdAdds</FONT></H3>
<P>The code for the kdAdds program is shown in Listings 14.1 through 14.8. Notice
the custom RC file and the <TT>include</TT> file for the project. These two 
tiny
files store error strings. In later versions of the program, these files will become
larger as more error strings are added to the code. For this release, all I have
done is stub out these files so that they can easily be expanded later.<BR>
<BR>

<A NAME="Heading10"></A><FONT COLOR="#000077"><B>Listing 14.1. The header for the
main module in the kdAdds program.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">///////////////////////////////////////

// File: Main.h

// Project: kdAdd

// Copyright 
(c) 1997 by Charlie Calvert

//

#ifndef MainH

#define MainH

#include &lt;Forms.hpp&gt;

#include &lt;StdCtrls.hpp&gt;

#include &lt;Controls.hpp&gt;

#include &lt;Classes.hpp&gt;

#include &lt;DBCtrls.hpp&gt;

#include &lt;Mask.hpp&gt;

#include 
&lt;DBGrids.hpp&gt;

#include &lt;Grids.hpp&gt;

#include &lt;Menus.hpp&gt;

#include &lt;ExtCtrls.hpp&gt;

#include &lt;ComCtrls.hpp&gt;

#include &lt;DBCGrids.hpp&gt;

#include &lt;vcl\Buttons.hpp&gt;

class TForm1 : public TForm

{

__published:

  
TMainMenu *MainMenu1;

  TMenuItem *Sorts1;

  TMenuItem *Last1;

  TMenuItem *First1;

  TMenuItem *Company1;

  TPanel *Panel1;

  TDBGrid *FirstLastGrid;

  TPageControl *PageControl1;

  TTabSheet *tsAddress;

  TTabSheet *tsPhone;

  TTabSheet 
*tsMemo;

  TDBGrid *DBGrid2;

  TDBMemo *DBMemo1;

  TDBCtrlGrid *DBCtrlGrid2;

  TLabel *Label1;

  TLabel *Label2;

  TLabel *Label3;

  TLabel *Label4;

  TLabel *Label5;

  TDBEdit *DBEdit1;

  TDBEdit *DBEdit2;

  TDBEdit *City;

  TDBEdit 
*DBEdit4;

  TDBEdit *Zip;

  TTabSheet *tsEMail;

  TDBCtrlGrid *DBCtrlGrid3;

  TLabel *Label12;

  TDBEdit *DBEdit10;

  TLabel *Label13;

  TDBEdit *DBEdit11;

  TLabel *Label14;

  TDBEdit *DBEdit12;

  TMenuItem *Table1;

  TMenuItem *Insert1;

  
TMenuItem *Delete1;

  TMenuItem *Post1;

  TSpeedButton *InsertBtn;

  TSpeedButton *PostBtn;

  TSpeedButton *DeleteBtn;

  TSpeedButton *CancelBtn;

  TMenuItem *Cancel1;

  TMenuItem *Seach1;

  TMenuItem *First2;

  TMenuItem *Last2;

  TMenuItem 
*Company2;

  TMenuItem *Help1;

  TMenuItem *Contents1;

  TMenuItem *N1;

  TMenuItem *About1;

  TTabSheet *AddInfo1;

  TLabel *Label15;

  TLabel *Label16;

  TLabel *Label17;

  TDBEdit *DBEdit13;

  TDBEdit *DBEdit14;

  TDBEdit *DBEdit15;

  
TDBCtrlGrid *DBCtrlGrid4;

  TLabel *Label18;

  TLabel *Label19;

  TLabel *Label20;

  TLabel *Label21;

  TLabel *Label22;

  TDBEdit *DBEdit17;

  TDBEdit *DBEdit18;

  TDBEdit *DBEdit19;

  TDBEdit *DBEdit20;

  TDBCtrlGrid *DBCtrlGrid5;

  
TLabel *Label23;

  TLabel *Label24;

  TLabel *Label25;

  TDBEdit *DBEdit21;

  TDBEdit *DBEdit22;

  TDBEdit *DBEdit23;

  TDBEdit *DBEdit6;

  TDBCtrlGrid *DBCtrlGrid1;

  TLabel *Label6;

  TLabel *Label7;

  TLabel *Label8;

  TDBEdit *DBEdit7;

  
TDBEdit *DBEdit8;

  TDBEdit *DBEdit16;

  void __fastcall Last1Click(TObject *Sender);

  void __fastcall Insert1Click(TObject *Sender);

  void __fastcall Cancel1Click(TObject *Sender);

  void __fastcall Delete1Click(TObject *Sender);

  void 
__fastcall Last2Click(TObject *Sender);

  void __fastcall About1Click(TObject *Sender);

  void __fastcall PostBtnClick(TObject *Sender);

private:

public:

  virtual __fastcall TForm1(TComponent* Owner);

};

extern TForm1 *Form1;

#endif


</FONT></PRE>
<P><A NAME="Heading11"></A><FONT COLOR="#000077"><B>Listing 14.2. The main module
for the kdAdds program.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">///////////////////////////////////////

// File: Main.cpp

// Project: KdAdd

// 
Copyright (c) 1997 by Charlie Calvert

//

#include &lt;vcl.h&gt;

#pragma hdrstop

#include &quot;Main.h&quot;

#include &quot;DMod1.h&quot;

#include &quot;Globals.h&quot;

#include &quot;AboutBox1.h&quot;

#pragma resource &quot;*.dfm&quot;

TForm1 
*Form1;

__fastcall TForm1::TForm1(TComponent* Owner)

  : TForm(Owner)

{

  PageControl1-&gt;ActivePage = AddInfo1;

}

void __fastcall TForm1::SetupIndex(TObject *Sender)

{

  switch (dynamic_cast&lt;TComponent *&gt;(Sender)-&gt;Tag)

  {

    
case 100:

      DMod-&gt;NamesTable-&gt;IndexName = &quot;idxLastName&quot;;

      break;

    case 101:

      DMod-&gt;NamesTable-&gt;IndexName = &quot;idxFirstName&quot;;

      break;

    case 102:

      DMod-&gt;NamesTable-&gt;IndexName = 
&quot;idxCompany&quot;;

      break;

    case 103:

      DMod-&gt;NamesTable-&gt;IndexName = &quot;&quot;;

      break;

  }

}

void __fastcall TForm1::IndexClick(TObject *Sender)

{

  SetupIndex(Sender);

  
DMod-&gt;NamesTable-&gt;FindNearest(OPENARRAY(TVarRec, (&quot;AAAA&quot;)));

}

void __fastcall TForm1::Insert1Click(TObject *Sender)

{

  switch (dynamic_cast&lt;TComponent&amp;&gt;(*PageControl1-&gt;ActivePage).Tag)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -