* DatasessionPass.prg *********************************************** * Sample code using DataSet class *********************************************** Local loSession1, loSession2 * Create 1st private datasession loSession1 = Createobject('Session1') loSession1.SomeQueries() && run some queries loSession2 = Createobject('Session2') loSession2.GetTheDataAndBrowse(loSession1) && transfer data from session1 Define Class session1 As Session DataSession = 2 && Private Procedure SomeQueries Select * From (_samples+'data\customer') Where country = 'USA' Into Cursor crsUSA Select ord.* From (_samples+'data\orders') ord ; INNER Join crsUSA On crsUSA.cust_id == ord.cust_id ; ORDER By ord.cust_id, ord.order_date ; INTO Cursor crsUSAOrders ; nofilter Endproc Procedure GetDataCursors( tcAliasList, tcAsAliasList ) If Empty(m.tcAsAliasList) tcAsAliasList = m.tcAliasList Endif Local laAlias[1], laAsAlias[1] Local oDataSetPacker As 'DataSet' Of Fullpath('DatasessionPass.prg') Local ix, lcAlias, lcAsAlias oDataSetPacker = Newobject('DataSet',Fullpath('DatasessionPass.prg')) Alines(laAsAlias, m.tcAsAliasList,1,',') For ix = 1 To Alines(laAlias, m.tcAliasList,1,',') lcAlias = laAlias[m.ix] lcAsAlias = Iif(m.ix > Alen( laAsAlias ), laAlias[m.ix], laAsAlias[m.ix] ) oDataSetPacker.AddTable(m.lcAlias, m.lcAsAlias) Endfor Return oDataSetPacker Endproc Enddefine Define Class session2 As Session DataSession = 2 && Private Procedure GetTheDataAndBrowse(toOtherSession) Local loDataSet loDataSet = toOtherSession.GetDataCursors( ; 'crsUSA, crsUSAOrders', 'crsCustomer,crsOrders' ) loDataSet.RestoreDataset(This.DataSessionId) Select crsCustomer Browse Select crsOrders Browse Endproc Enddefine *********************************************** * Sample code using DataSet class *********************************************** ************************************************************************************** ** Dataset class to pack given cursors into an object to pass between data sessions ************************************************************************************** Define Class DataSet As Custom TableCount = 0 DataSessionId = 0 Dimension TableInfo[1] Procedure Init This.DataSessionId = Set("Datasession") Endproc Procedure AddTable(tcAlias, tcAsAlias) Local Array aStruc[1],aStripped[1] Afields(aStruc,m.tcAlias) Dimension aStripped[ALEN(aStruc,1),5] For ix = 1 To Alen(aStruc,1) aStripped[m.ix,1] = aStruc[m.ix,1] aStripped[m.ix,2] = aStruc[m.ix,2] aStripped[m.ix,3] = aStruc[m.ix,3] aStripped[m.ix,4] = aStruc[m.ix,4] aStripped[m.ix,5] = aStruc[m.ix,5] Endfor This.TableCount = This.TableCount + 1 Dimension This.TableInfo[this.TableCount] This.TableInfo[this.TableCount] = Createobject('Custom') With This.TableInfo[this.TableCount] .AddProperty('aStructure[1]') .AddProperty('aRecords[1]') .AddProperty('Records') .AddProperty('Alias',m.tcAlias) .AddProperty('AsAlias', Iif(Empty(m.tcAsAlias),m.tcAlias,m.tcAsAlias) ) Acopy(aStripped, .aStructure) Select * From (m.tcAlias) Where !Deleted() Into Cursor __crsTemp__ nofilter .RecordS = Reccount() If .RecordS > 0 Dimension .aRecords[RECCOUNT()] Scan Scatter Name .aRecords[RECNO()] Memo Endscan Endif Use In '__crsTemp__' Endwith Endproc Procedure RestoreDataset(tnDataSessionID) && restore all with saved aliases For ix = 1 To This.TableCount This.Obj2Cursor( This.TableInfo[m.ix].Alias, '', m.tnDataSessionID ) Endfor Endproc Procedure Obj2Cursor( tcStoredAlias, tcAlias, tnDataSessionID ) Local ix,jx If !Empty(m.tnDataSessionID) Set DataSession To m.tnDataSessionID Endif For ix = 1 To This.TableCount With This.TableInfo[m.ix] If Upper(.Alias) == Upper(m.tcStoredAlias) tcAlias = Iif(Empty(m.tcAlias), .AsAlias, m.tcAlias ) Create Cursor (m.tcAlias) From Array .aStructure For jx = 1 To .RecordS Append Blank Gather Name .aRecords[m.jx] Memo Endfor Exit Endif Endwith Endfor Set DataSession To This.DataSessionId Endproc EnddefineCetin