在空白窗体上添加控件:
FDPhysSQLiteDriverLink1: TFDPhysSQLiteDriverLink;FDGUIxWaitCursor1: TFDGUIxWaitCursor;FDConnection1: TFDConnection;DataSource1: TDataSource;FDTable1: TFDTable;IWDBGrid1: TIWDBGrid;
在 OnCreate 事件中写代码:
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;
效果图:
TFDQuery 代替 TFDTable 重新测试:
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;