為通過 FireDAC(XE5開始支持的) 使用 SqLite, 現在已換成 XE6 + IntraWeb v14.0.32 Ultimate.
首先把官方提供的 C:\Users\Public\Documents\Embarcadero\Studio\14.0\Samples\data\FDDemo.sdb 復制到程序目錄下, 用於測試.
FDPhysSQLiteDriverLink1: TFDPhysSQLiteDriverLink; FDGUIxWaitCursor1: TFDGUIxWaitCursor; FDConnection1: TFDConnection; DataSource1: TDataSource; FDTable1: TFDTable; IWDBGrid1: TIWDBGrid;
procedure TIWForm1.IWAppFormCreate(Sender: TObject); begin FDTable1.Connection := FDConnection1; DataSource1.DataSet := FDTable1; IWDBGrid1.DataSource := DataSource1; FDConnection1.DriverName := 'SQLite'; FDConnection1.Params.Add('Database=FDDemo.sdb'); //如果測試數據在其他目錄, 如: Database=C:\Temp\FDDemo.sdb; 但要真放到網絡上恐怕有權限限制 FDTable1.TableName := 'Orders'; //Orders 是 FDDemo.sdb 中的一個表 FDTable1.Active := True; IWDBGrid1.Align := alClient; end;
procedure TIWForm1.IWAppFormCreate(Sender: TObject); begin FDQuery1.Connection := FDConnection1; DataSource1.DataSet := FDQuery1; IWDBGrid1.DataSource := DataSource1; FDConnection1.Open('DriverID=SQLite;Database=FDDemo.sdb'); FDQuery1.Open('SELECT * FROM Orders'); IWDBGrid1.Align := alClient; end;