Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Session Object
Message
From
07/12/2000 09:33:46
 
 
To
07/12/2000 06:08:59
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00450282
Message ID:
00450339
Views:
32
Kueh,

>Can someone enlighten me on the Session Object usage? Example codes would be usefull. Thanks.

You can define a class as Session in code, but not using the visual designers. It is useful for business objects or for wrapping blocks of existing code, since it automatically creates a private datasession without the overhead of a form.

This is sample business object code, but untested... maybe it will help get you started with some ideas.

* a simple base session class for data access
* (barebones, no error checking)
DEFINE CLASS busBase AS Session
cTableName = []
cError = []
oData = NULL

FUNCTION Init()
* various settings scoped to private session
SET EXCLUSIVE OFF
SET DELETED ON
* etc, etc
ENDFUNC

FUNCTION GetByID(nID)
* needs error-checking for empty param and property
SELECT * FROM (THIS.cTableName) ;
INTO CURSOR temp ;
WHERE pk = nID
IF _TALLY = 0
THIS.cError = [Item not found]
RETURN .f.
ELSE
SCATTER NAME THIS.oData
RETURN .t.
ENDIF
ENDFUNC

ENDDEFINE


* now create customer business object definition
DEFINE CLASS busCustomer AS busBase
cTableName = "customer"
ENDDEFINE

* save all of the above code in SessionTest.prg

* now use it
SET PROCEDURE TO SessionTest.prg ADDITIVE
oCustomer = CREATEOBJECT("busCustomer")
IF NOT oCustomer.GetByID(1234)
WAIT WINDOW [Error: ]+oCustomer.cError
ELSE
* get reference to SCATTERed object
* (optional -- you could just say oCustomer.oData.First, etc)
oCust = oCustomer.oData
* let's see what we got
WAIT WINDOW [Customer: ]+TRIM(oCust.First)+[ ]+TRIM(oCust.Last)
ENDIF
oCust = NULL
oCustomer = NULL

***************
*** you could also have a method to save changed info and
*** call it like this:
oCust.Address = [1234 Oak Street]
oCust.Active = .t.
oCust.CreditLimit = [500]
oCustomer.Save(1234)

* in the busBase Save method, you could USE the table,
* seek the correct record, then GATHER NAME THIS.oData
* (for other backends, this would of course be different)
David Stevenson, MCSD, 2-time VFP MVP / St. Petersburg, FL USA / david@topstrategies.com
Previous
Reply
Map
View

Click here to load this message in the networking platform