Aleniko


Hi;

I'm calling an older foxpro prg from a VFP9 form. The prg has a bunch of use commands which will inhterfere with the form, so I'd like to make sure I'm restoring the form's environment when I return from the prg.

- I'm not sure if I should use the session object for this purpose

I've tried to test this but I'm doing something wrong. I'm opening a different table and then calling this, but after the return, I still have ruginv open and at the bottom of file.

otest = CREATEOBJECT("mysession")
otest.datasessionid
USE ruginv
GO bott
RECNO()
SET DATASESSION TO 1
ALIAS()
RECNO()
RETURN

DEFINE CLASS mysession as Session
enddefine


Thanks.






Re: How to use the session object.

CetinBasoz


Aleniko,

You're creating the session but not using it:

CLEAR

CLOSE DATABASES all

otest = createobject("mysession") && could be createobject("session") - no custom PEM there

otest.datasessionid

set datasession to otest.datasessionid

use customer

go bott

recno(), alias(), aused(aC1)

set datasession to 1

recno(), alias(), aused(aC2)

release oTest && try commenting

use customer exclusive

alias(), isexclusive()

use

define class mysession as session

enddefine






Re: How to use the session object.

Naomi Nosonovsky

Hi Alen,

I usually use a slightly different approach. I have a base session class

Code Snippet

***** 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 DELETED ON
SET CENTURY ON
SET TALK OFF
SET EXCLUSIVE OFF
SET MULTILOCKS ON
SET EXACT ON
*SET ANSI ON && JMW
SET ANSI OFF
SET NEAR OFF
SET SAFETY OFF
DECLARE INTEGER UuidCreate IN rpcrt4.DLL STRING @ UUID && This DLL used for GUID creation
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
&& JMW Set the datasession to previous.
*-- CHANGE - NN - March 31, 2006 - 12:39:11
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

And then for my processes I create a subclass of this class and put the logic there. I actually have an extra class called BusinessProcess and make my classes to be subclasses of that class.

In your case, as Cetin said, if you don't want to move code into your session class, then you would have to switch session to new session's class DataSessionID.

e.g.

loNewSession = createobject('PrivateSession', thisform.DataSessionID)

set datasession to (m.loNewSession.DataSessionID) && We now switched to new DS ID

** do your process

release loNewSession && if you're using the class above, the DS ID would be restored automatically






Re: How to use the session object.

Aleniko

Thank you both for your input.

I tried this from a calling form. I've put a command button which runs this:

otest = createobject("session")
set datasession to otest.datasessionid
* CLOSE DATABASES all
DO stt2c
set datasession to thisform.DataSessionId
release oTest


I got this error, at the point when I try to set index in stt2c:
COMMAND CANNOT BE ISSUED ON A TABLE WITH CURSORS IN TABLE BUFFERING MODE.


Any ideas
Thanks.




Re: How to use the session object.

CetinBasoz

Isn't it self explanatory You can't index table buffered cursors/tables. Change buffering first.



Re: How to use the session object.

Naomi Nosonovsky

Hi Alen,

I agree with Cetin, it sounds like a different problem, when you try to index a table in table buffered mode.

Did you verify that you are now successfully running a new session (you may put SET command to see it).

Did you get this error on a line with INDEX ON

Also you may start a new thread if the original problem is solved.





Re: How to use the session object.

Aleniko

No - the original problem is not solved.

I have verified that I'm running a new session by checking the session id like this:
wait set("datasession") wind - which returned 3.

Yes, the command causeing the problem is "set index to balfor.idx" - which is an IDX of course.

So, my buffering carries on into the new session I have to turn buffering off in the new session and then set it up again when I release it

I'm confused. I'm basically trying to preserve my form's environment no matter what the called prg does.

Thanks.




Re: How to use the session object.

Naomi Nosonovsky

SET INDEX TO - I haven't used this command for quite a long time and I prefer to use structural indexes. Unfortunately, it may be not a solution for you, but if you haven't gone far with the development, try to convert all indexes to structural and use SET ORDER command instead.

If this is not an option for you, I'm not exactly sure.

Also, please note - that if you're using session class as is and not the class I gave you in my previous message (or some other class you can design) you're running with all default VFP settings for the data session. AFAIK in VFP9 the default for exclusive is OFF and some other settings may be correct too, but it's better to not take a chance and use your own session class or instantiate a Settings class if you have one, which sets all DS properties to your desired state (similar to what I showed in my sample).

Can you modify the called program If yes, then I would simply turn this program into a session based class.





Re: How to use the session object.

Aleniko

Naomi;

Yes, I can modify the calling program - its a form. But I can't see how would that help if the new session won't support idx. I'm not sure what is the reason for the buffering issue. Maybe because I'm using older IDX files...

In any case, thanks for your help including the session class.

Alen.




Re: How to use the session object.

Naomi Nosonovsky

Perhaps I was not clear again. I mean, can you modify the process code What exactly you're doing If you call one form from another and want both forms to run in separate DS, then you just set datasession to private for both forms and they would not interfere one with another.

As for using IDX and problems with separate DS, I'm not sure we're getting the full picture. I would still suggest to start a new thread and describe this particular problem as precise as you can.

I used IDXs for a very brief time in November working with some "old style" application. I got advice to convert to CDX if possible. I fully agree with this advice. You would be able to switch order in your tables for buffered/non buffered tables. You would not be able to CREATE a new index tag for table buffered table.