Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Smallest object in VFP 7
Message
De
11/12/2001 03:38:36
 
 
À
10/12/2001 22:16:38
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Divers
Thread ID:
00590364
Message ID:
00592548
Vues:
35
You can use the Decorator design pattern to wrap your class in a Session object:
#define TABLE_NAME "c:\temp\test.dbf"

set safety off
set exclusive off
clear

create table (TABLE_NAME) free (col1 i)
use (TABLE_NAME) 
select 0    

? program(), set("datasession")

loDecorator = createobject("DecoratorSession", createobject("test", TABLE_NAME))
? program(), set("datasession")
=loDecorator.populate()
=loDecorator.list()
? program(), set("datasession")
? alias()

define class DecoratorSession as custom

	protected DecoratedObject

	function init( toReference )
		if vartype(toReference) != 'O'
			return .f.
		endif
		this.DecoratedObject = toReference
	endfunc

	function this_access( tcMember )
		* BEWARE - any PEMs of the DecoratedObject that
		* are duplicated in THIS are inaccessable
		if pemstatus(this, tcMember, 5)
			return this
		else
			return this.DecoratedObject
		endif
	endfunc

	function destroy()
		this.DecoratedObject = null
	endfunc

enddefine

define class test as session

	function init( tcTableName )
		* remember that private datasessions require their own settings
		set exclusive off
		use (tcTableName)
	endfunc

	function populate

		? program(), set("datasession")

		local i, lnCount
		lnCount = 5
		for i = 1 to lnCount
			insert into (alias()) (col1) values (i)
		endfor
		return lnCount
	endfunc

	function list

		? program(), set("datasession")

		scan
			? col1
		endscan
		return reccount()
	endfunc

enddefine
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform