FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to save and restore SET RELATION?
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
How to save and restore SET RELATION?
Posted: Thu Sep 11, 2014 04:53 AM

Hi guys,

Anyone has a code snippet that they are willing to share on how to save and then later on restore SET RELATIONs?

TIA

FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to save and restore SET RELATION?
Posted: Thu Sep 11, 2014 09:47 AM

Check if DbRelation() can be of any help.

EMG

Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: How to save and restore SET RELATION?
Posted: Fri Sep 12, 2014 04:03 AM
Thanks for the reply Enrico.

Found code below at https://groups.google.com/forum/#!msg/c ... NKgI1etXgJ
Code (fw): Select all Collapse
private aHoldRelations := StoreRelation( )
private nHoldRecno := recno()
set relation to
.... do stuff ...
aHoldRelations := RestoreRelation( aHoldRelations )
go recno()
.... code ...


FUNCTION StoreRelation( )
  local aRelationStack := {}
  local nRelationLevel := 0
  do while dbrelation( nRelationLevel+1 ) > " "
     aadd( aRelationStack, Relation(++nRelationLevel) )
  enddo
return aRelationStack

FUNCTION Relation( nRelation )
  RETURN { DBRELATION(nRelation), ;
           ALIAS(DBRSELECT(nRelation)) }

FUNCTION RestoreRelation ( aRelationList )
  local aRelationLevel := 1
  local cExpression := ""
  local cWorkAlias := ""
  set relation to
  do while aRelationList{ aRelationLevel, 1 } > " "
     cExpression := aRelationList{ aRelationLevel, 1 }
     cWorkAlias := aRelationList{ aRelationLevel, 2 }
     dbSetRelation( cWorkAlias, &("{|| "+cExpression+"}"), cExpression)
     ++aRelationLevel
  enddo
return {}
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour

Continue the discussion