Delphi 仿DBNavigator方式

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;

Delphi程式建立有密碼的access資料庫

如何直接利用Delphi建立有password的access mdb database?

Use System.Win.ComObj;

procedure TForm1.Button1Click(Sender: TObject);
var cnewmdb:variant;
begin
  // 透過ADOX建立
  cnewmdb := CreateOleObject('ADOX.Catalog');
  cnewmdb.Create('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\test.MDB;Jet OLEDB:Database Password=''12345678'';' );
  
  // 連線
ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\TT2.MDB;Jet OLEDB:Database Password=''12345678'';';
  ADOConnection1.LoginPrompt:=false;
  ADOConnection1.connected:=true;
end;

Delphi XE FireDAC簡介影片

FireDAC 是一個企業級並可跨平台存取資料的開發庫,包含 Windows、Mac 和行
動裝置。FireDac 可以與 Delphi、C++Builder 和 RAD Studio 無縫地整合開發跨
平台的解決方案。FireDac 提供用戶支援市面上大部分的資料庫平台,包含
Oracle, Microsoft SQL Server, IBM DB2, SAP, DataSnap, Sybase SQL Anywhere,
InterBase, Advantage Database, PostgreSQL, SQLite, MySQL, Firebird, 和
Microsoft Acces。