📄 ch13.htm
字号:
case ctClose: Close(); break;
case ctInsert: DMod->AddressTable->Insert(); break;
case ctPrior: DMod->AddressTable->Prior(); break;
case ctEdit: HandleEditMode(); break;
case ctNext: DMod->AddressTable->Next(); break;
case ctCancel:
DMod->AddressTable->Cancel(); break;
case ctPrint: PrintData(ctPrint); break;
case ctFirst: DMod->AddressTable->First(); break;
case ctLast: DMod->AddressTable->Last(); break;
case ctPrintPhone:
PrintData(ctPrintPhone); break;
case ctPrintAddress: PrintData(ctPrintAddress); break;
case ctPrintAll: PrintData(ctPrintAll); break;
case ctDelete:
AnsiString S = DMod->AddressTableLName->AsString;
if
(MessageBox(Handle, "Delete?", S.c_str(), MB_YESNO) == ID_YES)
DMod->AddressTable->Delete();
break;
}
}
void TForm1::HandleEditMode()
{
InsertBtn->Enabled = !DMod->AddressSource->AutoEdit;
CancelBtn->Enabled = !DMod->AddressSource->AutoEdit;
DeleteBtn->Enabled = !DMod->AddressSource->AutoEdit;
if (!DMod->AddressSource->AutoEdit)
{
SetReadOnly(True);
EditBtn->Caption = "Stop Edit";
Caption = FCaptionString + EDIT_MODE_STRING;
}
else
{
if (DMod->AddressTable->State != dsBrowse)
DMod->AddressTable->Post();
SetReadOnly(False);
EditBtn->Caption = "Goto Edit";
Caption =
FCaptionString + READ_ONLY_STRING;
}
}
void TForm1::PrintData(TCommandType Command)
{
}
void TForm1::SetReadOnly(BOOL NewState)
{
DMod->AddressSource->AutoEdit = NewState;
}
void __fastcall
TForm1::AddressSourceStateChange(TObject *Sender)
{
AnsiString S;
switch (DMod->AddressTable->State)
{
case dsInactive:
S = "Inactive";
break;
case dsBrowse:
S = "Browse";
break;
case dsEdit:
S = "Edit";
break;
case dsInsert:
S = "Insert";
break;
case dsSetKey:
S = "SetKey";
break;
}
StatusBar1->SimpleText = "State:
" + S;
}
void __fastcall TForm1::AddressSourceDataChange(TObject *Sender,
TField *Field)
{
HBITMAP BulbOn, BulbOff;
Caption = DMod->AddressTable->FieldByName("Marked")->AsString;
if
(DMod->AddressTable->FieldByName("Marked")->AsBoolean)
{
BulbOn = LoadBitmap((HINSTANCE)HInstance, "BulbOn");
SpeedButton1->Glyph->Handle = BulbOn;
}
else
{
BulbOff =
LoadBitmap((HINSTANCE)HInstance, "BulbOff");
SpeedButton1->Glyph->Handle = BulbOff;
}
}
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
DMod->AddressTable->Edit();
DMod->AddressTableMarked->AsBoolean = !DMod->AddressTableMarked->AsBoolean;
DMod->AddressTable->Post();
}
void __fastcall TForm1::FormShow(TObject *Sender)
{
DMod->AddressSource->OnStateChange =
AddressSourceStateChange;
AddressSourceStateChange(NULL);
DMod->AddressSource->OnDataChange = AddressSourceDataChange;
AddressSourceDataChange(NULL, NULL);
}
void __fastcall TForm1::About1Click(TObject *Sender)
{
AboutBox->ShowModal();
}
void __fastcall TForm1::CommandSortClick(TObject *Sender)
{
DoSort(Sender);
DMod->AddressTable->FindNearest(OPENARRAY(TVarRec, ("AAAA")));
}
void __fastcall TForm1::CommandSearchClick(TObject
*Sender)
{
AnsiString S;
if (InputQuery("Search Dialog", "Enter Name", S))
{
DoSort(Sender);
DMod->AddressTable->FindNearest(OPENARRAY(TVarRec, (S)));
}
}
TColor TForm1::GetColor(TObject *Sender)
{
switch (dynamic_cast<TComponent *>(Sender)->Tag)
{
case ccForm:
return Form1->Color;
break;
case ccEdit:
return FNameEdit->Color;
break;
case ccEditText:
return
FNameEdit->Font->Color;
break;
case ccLabel:
return Label2->Color;
break;
case ccPanel:
return Panel1->Color;
break;
}
}
void __fastcall TForm1::CommandColorClick(TObject *Sender)
{
ColorDialog1->Color = GetColor(Sender);
if (!ColorDialog1->Execute())
return;
switch (dynamic_cast<TComponent *>(Sender)->Tag)
{
case ccForm:
Form1->Color = ColorDialog1->Color;
break;
case
ccEdit:
SetEdits(ColorDialog1->Color);
break;
case ccEditText:
SetEditText(ColorDialog1->Color);
break;
case ccLabel:
SetLabels(ColorDialog1->Color);
break;
case ccPanel:
SetPanels(ColorDialog1->Color);
break;
}
}
void TForm1::SetEdits(TColor Color)
{
int i;
for (i = 0; i < ComponentCount; i++)
{
if (dynamic_cast<TDBEdit *>(Components[i]))
dynamic_cast<TDBEdit
*>(Components[i])->Color = Color;
else if (dynamic_cast<TDBGrid *>(Components[i]))
dynamic_cast<TDBGrid *>(Components[i])->Color = Color;
else if (dynamic_cast<TDBMemo *>(Components[i]))
dynamic_cast<TDBMemo *>(Components[i])->Color = Color;
else if (dynamic_cast<TDBLookupComboBox *>(Components[i]))
dynamic_cast<TDBLookupComboBox *>(Components[i])->Color = Color;
}
}
void
TForm1::SetEditText(TColor Color)
{
int i;
for (i = 0; i < ComponentCount; i++)
{
if (dynamic_cast<TDBEdit *>(Components[i]))
dynamic_cast<TDBEdit *>(Components[i])->Font->Color = Color;
else if
(dynamic_cast<TDBGrid *>(Components[i]))
dynamic_cast<TDBGrid *>(Components[i])->Font->Color = Color;
else if (dynamic_cast<TDBMemo *>(Components[i]))
dynamic_cast<TDBMemo
*>(Components[i])->Font->Color = Color;
else if (dynamic_cast<TDBLookupComboBox *>(Components[i]))
dynamic_cast<TDBLookupComboBox *>(Components[i])->Font->Color = Color;
}
}
void TForm1::SetLabels(TColor
Color)
{
int i;
for (i = 0; i < ComponentCount; i++)
if (dynamic_cast<TLabel *>(Components[i]))
dynamic_cast<TLabel *>(Components[i])->Font->Color = Color;
}
void TForm1::SetPanels(TColor Color)
{
int i;
for (i = 0; i < ComponentCount; i++)
if (dynamic_cast<TPanel *>(Components[i]))
dynamic_cast<TPanel *>(Components[i])->Color = Color;
}
void __fastcall TForm1::System1Click(TObject *Sender)
{
SetEdits(clWindow);
SetEditText(clBlack);
SetLabels(clBlack);
SetPanels(clBtnFace);
Form1->Color = clBtnFace;
}
void __fastcall
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -