Use data connection pooling (Tiwdatamodulepool).
When creating a new project, check the Pool Data Connections:
The new Pool (Tiwdatamodulepool) is placed on the Servercontroller form (which is also a data module) and needs to know the change is that it adds two functions:
function LockDataModule: TDataModule1;
procedure UnlockDataModule(ADataModule: TDataModule1);
At the same time, the Wizard also automatically generated a special data module datamoduleunit;
Place the data source related controls on the Datamoduleunit form first:
FDPhysSQLiteDriverLink1: TFDPhysSQLiteDriverLink;
FDGUIxWaitCursor1: TFDGUIxWaitCursor;
FDConnection1: TFDConnection;
DataSource1: TDataSource;
FDTable1: TFDTable;
Then write the code in its OnCreate event:
procedure TDataModule1.DataModuleCreate (Sender: TObject);
begin
FDTable1.Connection: = FDConnection1;
DataSource1.DataSet: = FDTable1;
FDConnection1.DriverName: = ‘SQLite’;
FDConnection1.Params.Add (‘Database = FDDemo.sdb’); // Don't forget to copy FDDemo.sdb to the program directory
FDTable1.TableName: = ‘Orders’;
// FDTable1.Active: = True;
end;
Finally, return to the main form, first put a iwdbgrid1:tiwdbgrid; Then write the code:
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;
: