Generally, the data source related control should have the unified management of the data module, which is also convenient for other forms to call; Usersessionunit is a ready-made data module.
Now put the data source related controls on the Usersessionunit form:
FDPhysSQLiteDriverLink1: TFDPhysSQLiteDriverLink;
FDGUIxWaitCursor1: TFDGUIxWaitCursor;
FDConnection1: TFDConnection;
DataSource1: TDataSource;
FDTable1: TFDTable;
and write the code in its OnCreate event:
procedure TIWUserSession.IWUserSessionBaseCreate(Sender: TObject);
begin
FDTable1.Connection := FDConnection1;
DataSource1.DataSet := FDTable1;
FDConnection1.DriverName := ‘SQLite‘;
FDConnection1.Params.Add(‘Database=FDDemo.sdb‘);
FDTable1.TableName := ‘Orders‘;
FDTable1.Active := True;
end;
Only Iwdbgrid1:tiwdbgrid is left on the main form, and its code is simpler:
uses ServerController; {for UserSession}
procedure TIWForm1.IWAppFormCreate (Sender: TObject);
begin
IWDBGrid1.DataSource: = UserSession.DataSource1;
IWDBGrid1.Align: = alClient;
end;
: