- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "SQL.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- TBookmark SavePlace;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button9Click(TObject *Sender)
- {
- SavePlace=Form1->Query1->GetBookmark();
- //在当前位置设置一个书签
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button10Click(TObject *Sender)
- {
- if (SavePlace!="")
- {
- Form1->Query1->GotoBookmark(SavePlace);
- //跳转到指定书签
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Query1BeforeClose(TDataSet *DataSet)
- {
- if (Form1->Query1->Modified)
- {
- if (MessageDlg("数据库已经被修改过,是否保存结果?", mtWarning, TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes)
- Query1->Post();
- else
- Query1->Cancel();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button3Click(TObject *Sender)
- {
- Form1->Query1->Insert();
- //插入一条新的记录
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
- {
- if (!Form1->Query1->Modified)
- {
- if (MessageDlg("数据库已经被修改过,是否保存结果?", mtWarning, TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes)
- Query1->Post();
- else
- Query1->Cancel();
- }
- Query1->Close();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button4Click(TObject *Sender)
- {
- Form1->Query1->Delete();
- //删除一条记录
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button5Click(TObject *Sender)
- {
- Form1->Query1->First();
- //移动到第一条记录
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button6Click(TObject *Sender)
- {
- Form1->Query1->Last();
- //移动到最后一条记录
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button7Click(TObject *Sender)
- {
- Form1->Query1->Prior();
- //移动到前一条记录
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button8Click(TObject *Sender)
- {
- Form1->Query1->Next();
- //移动到下一条记录
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- Form1->Query1->Close();
- //关闭数据库
- Form1->Query1->SQL->Clear();
- //清除SQL语句
- Form1->Query1->SQL->Add(Form1->Memo1->Text);
- //读入新的SQL语句
- Form1->Query1->Open();
- //打开数据库
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- Form1->Memo1->Clear();
- //清除文本框中的内容
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Timer1Timer(TObject *Sender)
- {
- if (Form1->Query1->Eof)
- {
- Form1->Button6->Enabled=false;
- Form1->Button8->Enabled=false;
- }
- else
- {
- Form1->Button6->Enabled=true;
- Form1->Button8->Enabled=true;
- }
- if (Form1->Query1->Bof)
- {
- Form1->Button5->Enabled=false;
- Form1->Button7->Enabled=false;
- }
- else
- {
- Form1->Button5->Enabled=true;
- Form1->Button7->Enabled=true;
- }
- //动态设置按钮的有效状态
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- Form1->Memo1->Clear();
- //清空文本框
- Form1->Timer1->Enabled=true;
- //设置控件的有效状态
- }
- //---------------------------------------------------------------------------