主页 > 编程资料 > Delphi >
发布时间:2015-09-22 作者:网络 阅读:149次

Delphi有很好用的DBNavitor元件,美中不足的是按钮的样式稍嫌不足!那是否可以仿DBNavigator的方式?笔者提供一个简单的范例给大家 :)delphi_simulate_dbnavigator一、自订首笔/上笔/下笔/末笔
procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);begin  BtnFirst.Enabled := not Datasource1.DataSet.Bof;  BtnPrior.Enabled := not Datasource1.DataSet.Bof;  BtnNext.Enabled := not Datasource1.DataSet.eof;  BtnLast.Enabled := not Datasource1.DataSet.eof;  if TDataSource(Sender).State in [dsEdit,dsInsert]  then begin    BtnFirst.Enabled := False;    BtnPrior.Enabled := False;    BtnNext.Enabled := False;    BtnLast.Enabled := False;  end;end;二、自订新增/修改/删除/取消/存档
procedure TForm1.DataSource1StateChange(Sender: TObject);begin  BtnAdd.Enabled := TDataSource(Sender).State in [dsbrowse];  BtnEdit.Enabled := TDataSource(Sender).State in [dsbrowse];  BtnDelete.Enabled := TDataSource(Sender).State in [dsBrowse];  BtnAbort.Enabled := TDataSource(Sender).State in [dsEdit,dsInsert];  BtnSave.Enabled := TDataSource(Sender).State in [dsEdit,dsInsert];end;三、让button按下后与DBNavigator一样
procedure TForm1.BtnAbortClick(Sender: TObject);begin  dbnavigator1.BtnClick(nbcancel);end; procedure TForm1.BtnAddClick(Sender: TObject);begin  dbnavigator1.BtnClick(nbinsert);end; procedure TForm1.BtnDeleteClick(Sender: TObject);begin  dbnavigator1.BtnClick(nbdelete);end; procedure TForm1.BtnEditClick(Sender: TObject);begin  dbnavigator1.BtnClick(nbedit);end; procedure TForm1.BtnFirstClick(Sender: TObject);begin  dbnavigator1.BtnClick(nbfirst);end; procedure TForm1.BtnLastClick(Sender: TObject);begin  dbnavigator1.BtnClick(nblast);end; procedure TForm1.BtnNextClick(Sender: TObject);begin  dbnavigator1.BtnClick(nbnext);end; procedure TForm1.BtnPriorClick(Sender: TObject);begin  dbnavigator1.BtnClick(nbprior);end; procedure TForm1.BtnSaveClick(Sender: TObject);begin  dbnavigator1.BtnClick(nbpost);end;
关键字词: