一般情況下, 數據源相關控件應該有數據模塊中統一管理, 這也方便其他窗體調用; UserSessionUnit 就是一個現成的數據模塊.
FDPhysSQLiteDriverLink1: TFDPhysSQLiteDriverLink; FDGUIxWaitCursor1: TFDGUIxWaitCursor; FDConnection1: TFDConnection; DataSource1: TDataSource; FDTable1: TFDTable;
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;
uses ServerController; {為使用 UserSession} procedure TIWForm1.IWAppFormCreate(Sender: TObject); begin IWDBGrid1.DataSource := UserSession.DataSource1; IWDBGrid1.Align := alClient; end;