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

📄 ch11.htm

📁 好书《C++ Builder高级编程技术》
💻 HTM
📖 第 1 页 / 共 5 页
字号:

    DBGrid1->Options = TDBGridOptions(DBGrid1->Options) >> dgColLines;

  else

    DBGrid1->Options = TDBGridOptions(DBGrid1->Options) 
<< dgColLines;

  ColLines1->Checked = DBGrid1->Options.Contains(dgColLines);

}

void __fastcall TForm1::RowLines1Click(TObject *Sender)

{

  if (DBGrid1->Options.Contains(dgRowLines))

    DBGrid1->Options = 
TDBGridOptions(DBGrid1->Options) >> dgRowLines;

  else

    DBGrid1->Options = TDBGridOptions(DBGrid1->Options) << dgRowLines;

  RowLines1->Checked = DBGrid1->Options.Contains(dgRowLines);

}

void __fastcall 
TForm1::ShowAllOptions1Click(TObject *Sender)

{

  ShowOptionsForm->ShowOptions(DBGrid1->Options);

}

void __fastcall TForm1::MustPressF2orEntertoEdit1Click(TObject *Sender)

{

  DBGrid1->Options = TDBGridOptions(DBGrid1->Options) 
>> dgAlwaysShowEditor;

  MustPressF2orEntertoEdit1->Checked =

    !TDBGridOptions(DBGrid1->Options).Contains(dgAlwaysShowEditor);

}

void __fastcall TForm1::ChangeWidthofField1Click(TObject *Sender)

{

  AnsiString S("");

  
TColumn *Column = DBGrid1->Columns->Items[DBGrid1->SelectedIndex];

  if (InputQuery("Data Needed", "New Width of Selected Field", S))

    Column->Width = S.ToInt();

}

void __fastcall 
TForm1::HideCurrentColumn1Click(TObject *Sender)

{

  if (MessageBox(Handle, "Hide Column?",

       "Hide Info?", MB_YESNO | MB_ICONQUESTION) == ID_YES)

  {

    TColumn *Column = 
DBGrid1->Columns->Items[DBGrid1->SelectedIndex];

    Column->Free();

  }

}

void __fastcall TForm1::MoveCurrentColumn1Click(TObject *Sender)

{

  AnsiString S("");

  if (InputQuery("Data Needed", "Enter new 
position of column", S))

  {

    DMod->OrdersTable->Fields[DBGrid1->SelectedIndex]->Index = S.ToInt();

  }

}

</FONT></PRE>
<P><A NAME="Heading29"></A><FONT COLOR="#000077"><B>Listing 11.5. The data module
for the GridTricks 
program.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">///////////////////////////////////////

// File: ColumnEditor1.cpp

// Project: GridTricks

// Copyright (c) 1997 by Charlie Calvert

#include &lt;vcl\vcl.h&gt;

#pragma hdrstop

#include 
&quot;DMod1.h&quot;

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

TDMod *DMod;

__fastcall TDMod::TDMod(TComponent* Owner)

  : TDataModule(Owner)

{

}

void TDMod::GetFieldNames(TStringList *Items)

{

  int i;

  Items-&gt;Clear();

  for (i = 0; i &lt; 
OrdersTable-&gt;FieldCount - 1; i++)

    Items-&gt;Add(OrdersTable-&gt;Fields[i]-&gt;FieldName);

}

void TDMod::GetObjectNames(TStringList *Items)

{

  int i;

  Items-&gt;Clear();

  for (i = 0; i &lt; OrdersTable-&gt;FieldCount - 1; i++)

    
Items-&gt;Add(OrdersTable-&gt;Fields[i]-&gt;Name);

}

</FONT></PRE>
<P><A NAME="Heading30"></A><FONT COLOR="#000077"><B>Listing 11.6. The Column Editor
for the GridTricks program.</B></FONT></P>
<PRE><FONT 
COLOR="#0066FF">///////////////////////////////////////

// File: ColumnEditor1.cpp

// Project: GridTricks

// Copyright (c) 1997 by Charlie Calvert



// The last build of BCB I checked this on before shipping

// was still broken. BCB was not 
properly updating the

// data on the grids. Hopefully this program will start

// working properly once there is an update for BCB 1.0.

// The code I have here works fine in Delphi. In short, the

// problem is not in my code, and its not in the 
VCL. Its a

// BCB problem.

//

// Check my website for updates: users.aol.com/charliecal

//

#include &lt;vcl\vcl.h&gt;

#pragma hdrstop

#include &quot;ColumnEditor1.h&quot;

#include &quot;DMod1.h&quot;

#include &quot;Main.h&quot;

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

#define GAP 2



TColumnEditor *ColumnEditor;

//--------------------------------------------------------------------------

__fastcall TColumnEditor::TColumnEditor(TComponent* Owner)

  : TForm(Owner)

{

}



void 
TColumnEditor::CreateCheckBox(int Index, AnsiString Name, BOOL Visible)

{

  CheckBoxAry[Index] = (TCheckBox*) new TCustomCheckBox(this);

  CheckBoxAry[Index]-&gt;Parent = ColumnEditor;

  CheckBoxAry[Index]-&gt;Caption = Name;

  
CheckBoxAry[Index]-&gt;Left = 10;

  CheckBoxAry[Index]-&gt;Top = Index * (CheckBoxAry[Index]-&gt;Height + GAP);

  CheckBoxAry[Index]-&gt;Width = 200;

  CheckBoxAry[Index]-&gt;Checked = Visible;

}



void TColumnEditor::ShowColumns(void)

{

  int 
i;

  TColumn *Column;



  for (i = 0; i &lt; DMod-&gt;OrdersTable-&gt;FieldCount; i++)

    CreateCheckBox(i, DMod-&gt;OrdersTable-&gt;Fields[i]-&gt;Name,

      DMod-&gt;OrdersTable-&gt;Fields[i]-&gt;Visible);

  Height = 
(DMod-&gt;OrdersTable-&gt;FieldCount - 1) * (CheckBoxAry[0]-&gt;Height + GAP);

  if (Height &gt; 470)

    Height = 470;

  ShowModal();

  for (i = 0; i &lt; DMod-&gt;OrdersTable-&gt;FieldCount; i++)

    
DMod-&gt;OrdersTable-&gt;Fields[i]-&gt;Visible = CheckBoxAry[i]-&gt;Checked;

}

</FONT></PRE>
<P><A NAME="Heading31"></A><FONT COLOR="#000077"><B>Listing 11.7. The NamesDlg for
the GridTricks program.</B></FONT></P>
<PRE><FONT 
COLOR="#0066FF">///////////////////////////////////////

// File: NamesDlg.cpp

// Project: GridTricks

// Copyright (c) 1997 by Charlie Calvert

#include &lt;vcl\vcl.h&gt;

#pragma hdrstop

#include &quot;NamesDlg.h&quot;

#include 
&quot;DMod1.h&quot;

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

TNamesDialog *NamesDialog;

__fastcall TNamesDialog::TNamesDialog(TComponent* Owner)

  : TForm(Owner)

{

}

void TNamesDialog::ShowNames(TFieldData FieldData)

{

  switch(FieldData)

  {

    
case fdFieldNames:

      DMod-&gt;GetFieldNames((TStringList *)ListBox1-&gt;Items);

      break;

    case fdObjectNames:

      DMod-&gt;GetObjectNames((TStringList *)ListBox1-&gt;Items);

      break;

  }

  Show();

}

void __fastcall 
TNamesDialog::BitBtn1Click(TObject *Sender)

{

  Close();

}

</FONT></PRE>
<P><A NAME="Heading32"></A><FONT COLOR="#000077"><B>Listing 11.8. The ShowOptions
module shows which DBGrid options are currently active.</B></FONT></P>
<PRE><FONT 
COLOR="#0066FF">#include &lt;vcl\vcl.h&gt;

#pragma hdrstop

#include &quot;ShowOptions1.h&quot;

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

TShowOptionsForm *ShowOptionsForm;

__fastcall TShowOptionsForm::TShowOptionsForm(TComponent* Owner)

  : 
TForm(Owner)

{

  int i;

  int j = 0;

  for (i = 0; i &lt; ComponentCount; i++)

    if (dynamic_cast&lt;TCheckBox*&gt;(Components[i]))

    {

      CheckBox[j] = (TCheckBox*)Components[i];

      j++;

    }

}

void 
TShowOptionsForm::ShowOptions(TDBGridOptions Options)

{

  int i;

  for (i = 0; i &lt; 12; i++)

    if (Options.Contains(i))

      CheckBox[i]-&gt;Checked = True;

    e

⌨️ 快捷键说明

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