Microsoft KB Archive/248116

= How To Use the Session Class to Provide a Private Data Session =

Article ID: 248116

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft Visual Studio 6.0 Service Pack 3
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q248116



SUMMARY
Visual Studio 6.0 Service Pack 3 added the Session Class to Visual FoxPro. This class allows you to create a private data session without the use of a form. The benefit to this is that it allows you to create a lightweight (in terms of resource usage) custom object with encapsulated data. You previously would have needed a form, with all its associated overhead, or an empty formset to do this.

One of the best places to use this is in multithreaded DLLs (also added in Service Pack 3) since resource usage is at a premium in most cases where you would be using them.



MORE INFORMATION
An example of how to use this new class follows.

DEFINE CLASS myPrivateDSClass AS session

PROCEDURE UseTable *!* By using the table inside a method of the session object, *!* you are working in the object's DataSession. LPARAMETER tcTable IF NOT USED(tcTable) USE (tcTable) IN 0 ENDif ENDproc

PROCEDURE Destroy CLOSE DATA ALL ENDproc

To see this class in action, save the above code into MyDS.prg, and then run the following code: CREATE TABLE myDSTest (cTest C(10)) USE DBF SHARED FOR i = 1 TO 10 INSERT INTO myDSTest ; VALUES (TRANSFORM(i)) ENDfor
 * !* CREATE TABLE makes an exclusively-used table. USE DBF SHARED is
 * !* a good method for not having to remember the path to the table.

oDS = NEWOBJECT("myPrivateDSClass", "MyDS.prg") oDS.UseTable("myDSTest") SET
 * !* NEWOBJECT allows you to specify a class in a program or other
 * !* location without the use of SET CLASSLIB TO ... ADDITIVE.

WAIT WINDOW "Suspending... RESUME to remove Session Object." NOWAIT SUSPEND
 * !* The following line is needed to keep oDS in scope, so you can
 * !* see the datasession.

SET opens the Data Session window. If you switch between the default data session and MyPrivateDS, you see myDSTest open in both, with the record pointer at the top of one and the bottom of the other.

