Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adding a event to an object
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 6 SP5
OS:
Windows XP SP2
Network:
Windows 2000 Server
Miscellaneous
Thread ID:
01315742
Message ID:
01315940
Views:
15
Selim,

Maybe a wrapper class can help? Something like this (not tested carefully, no error handling, nothing, just an idea)

The wrapper will keep a count of accesses and assigns of the property nValue of the class 'myClass' which is the one you are not supposed to have access to, I just defined here for testing purposes only.

The idea is that the wrapper has a member that is set to an instance of the mysterious class in it's init, and it also has a property with the same name as the one you want to control, and you add an access an assign method to it, where you can do whatever you want but also set the property of the master class. Now, to use the wrapper as a 'Delegate' you add a this_access method that will check if the property is "native" (ie belongs to the wrapper class) in which case it will return this, other wise it will assume it is a property or method of the "master" class so it will return that object (this.myClassInstance in the sample)
clear
loMyWrapper		= Createobject('myWrapper')

? loMyWrapper.nValue
loMyWrapper.nValue = 9
? loMyWrapper.nValue
? loMyWrapper.ShowMessage('Testing') && ShowMessage is a method of myClass
? 'nValue access count: ', loMyWrapper.nValueAccessCount
? 'nValue assign count: ', loMyWrapper.nValueAssignCount

define class myClass as Session
	nValue = 0
	
	function showMessage(tcMessage)
		Messagebox(tcMessage)
	endfunc
enddefine

define class myWrapper as Session
	protected myClassInstance, Ready
	myClassInstance = null
	Ready = .f.
	nValueAccessCount = 0
	nValueAssignCount = 0
	nValue = 0

	function init()
		this.myClassInstance = Createobject('myClass')
		this.nValue = this.myClassInstance.nValue
		this.Ready = .t.
		return .t.
	endfunc
	
	function nValue_Assign(txNewValue)
		this.nValueAssignCount = this.nValueAssignCount + 1 
		this.nValue = txNewValue
		this.myClassInstance.nValue = txNewValue
	endfunc

	function nValue_Access()
		this.nValueAccessCount = this.nValueAccessCount + 1 
		return this.myClassInstance.nValue
	endfunc

	function this_Access(tcProperty)
		return Iif(this.Ready and not Pemstatus(this, tcProperty, 5), this.myClassInstance, this)
	endfunc

enddefine
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Previous
Reply
Map
View

Click here to load this message in the networking platform