使用數據連接池(TIWDataModulePool).
function LockDataModule: TDataModule1; procedure UnlockDataModule(ADataModule: TDataModule1);
FDPhysSQLiteDriverLink1: TFDPhysSQLiteDriverLink; FDGUIxWaitCursor1: TFDGUIxWaitCursor; FDConnection1: TFDConnection; DataSource1: TDataSource; FDTable1: TFDTable;
procedure TDataModule1.DataModuleCreate(Sender: TObject); begin FDTable1.Connection := FDConnection1; DataSource1.DataSet := FDTable1; FDConnection1.DriverName := 'SQLite'; FDConnection1.Params.Add('Database=FDDemo.sdb'); //別忘了把 FDDemo.sdb 復制到程序目錄下 FDTable1.TableName := 'Orders'; // FDTable1.Active := True; end;
uses DataModuleUnit, ServerController; procedure TIWForm1.IWAppFormCreate(Sender: TObject); var fDataModule: TDataModule1; begin fDataModule := LockDataModule; IWDBGrid1.DataSource := fDataModule.DataSource1; fDataModule.FDTable1.Active := True; UnlockDataModule(fDataModule); IWDBGrid1.Align := alClient; end;