* 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)