现在把数据源相关控件放在 UserSessionUnit 的窗体上:
FDPhysSQLiteDriverLink1: TFDPhysSQLiteDriverLink;FDGUIxWaitCursor1: TFDGUIxWaitCursor;FDConnection1: TFDConnection;DataSource1: TDataSource;FDTable1: TFDTable;
并在其 OnCreate 事件中写代码:
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;
主窗体上只留了 IWDBGrid1: TIWDBGrid, 其代码更简单了:
uses ServerController; {为使用 UserSession}procedure TIWForm1.IWAppFormCreate(Sender: TObject);begin IWDBGrid1.DataSource := UserSession.DataSource1; IWDBGrid1.Align := alClient;end;
效果图: