Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to Create a New Datasession
Message
 
 
To
21/03/2007 13:51:20
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01206682
Message ID:
01206685
Views:
18
This message has been marked as a message which has helped to the initial question of the thread.
>I would like to create a new private datasession for a common module in order to isolate database changes this module will make from the calling module.
>
>In other words, in the common routine, I would like to tell VFP: give me a new datasession that no one else is using.
>
>Is this possible? If so, how can I do it? Thanks.

Chaim,

Use it like this
loSession = createobject('PrivateSession')

Also for settings you may use settings class rather than hard-coding as in this sample.
***** Class definition for private session
DEFINE CLASS PrivateSession AS SESSION
* Previous data session ID
	nPriorDataSession = SET('DATASESSION')
* Status Bar settings
	cOldStatusBar = SET('status bar')
* ON Error settings
	cOnError = ON('error')
* ON Escape settings
	cOnEscape = ON('escape')

	PROCEDURE INIT
	LPARAMETER tnPriorDataSession

*--- scoped to data session...
       ** Set all usual DE settings such as SET TALK, SET EXCLUSIVE, etc., preferably by using special settings class.
	IF NOT EMPTY(m.tnPriorDataSession)
		THIS.nPriorDataSession = m.tnPriorDataSession
	ENDIF
	ENDPROC

	PROCEDURE DESTROY
	DODEFAULT()
	IF THIS.cOldStatusBar='ON'
		SET STATUS BAR ON
	ELSE
		SET STATUS BAR OFF
	ENDIF
	LOCAL lcOnEscape, lcOnError
	lcOnEscape = THIS.cOnEscape
	lcOnError = THIS.cOnError
	ON ESCAPE &lcOnEscape
	ON ERROR &lcOnError
	LOCAL ARRAY laSessions[1]
	=ASESSIONS(laSessions)
	IF ASCAN(laSessions, THIS.nPriorDataSession) > 0 && Make sure that the session still exists
		SET DATASESSION TO (THIS.nPriorDataSession)
	ENDIF

	ENDPROC

	PROCEDURE RELEASE
	RELEASE THIS
	ENDPROC

ENDDEFINE
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform