What should THIS_Access be used for?
See Decorating With This Access
From the VFP help:
A new global class method, THIS_ACCESS, has been added to Visual FoxPro 6.0. The code in a THIS_ACCESS method is executed whenever you attempt to change the value of a member of an object or a member of an object is queried.
Note that THIS_ACCESS is not intended to be a global replacement for Access and Assign methods - it only provides information about which object member is accessed or queried. Unlike an Access or Assign method, THIS_ACCESS does not provide control over values returned to specific object members.
THIS_Access can be used to implement a global Access / Assign handler. This allows some interesting usage scenations. For more information see the following two articles, which demonstrates how to implements a global application preferences object.
Global access and Assign events :
Streamline configuration by assigning global options with Access and Assign events
(Updated on [2007.09.07 08:40:58 AM GMT] )
Note that this_access *must* return an object, or else you get a type mismatch error when accessing any property.
-- Dragan Nedeljkovich
For an example of what THIS_Access is good for see Parameter Object Example.
Is there any way to get an object to act like many of the COM collections, where you can get results for
loMyCollection(5) ? (Something like a default property, where if no property is specified the Items array is accessed) It seems that the THIS_Access method should be able to accomplish this, but currently isn't designed to do this. - ?wgcs
I've been playing with this a lot lately, and the answer is no. Besides, default properties are going away, according to the stuff I've been reading on the MS .Net Web site. -- Doug Hennig
It's nice to have an answer... Now I can stop trying! Honestly, at first I found default properties unintuitive, but once I got used to them in collections, not being able to make a "real" collection myself in VFP seemed limiting. -- wgcs
THIS_Access is not (always) called when using WITH ... ENDWITH.
obj = create("test")
DEFINE CLASS test AS CUSTOM
? "THIS_Access", cMember
Is the right Question "What should THIS_Access be used for?" or "Can THIS_Access really be used?"
VFP 9.0 is cool :-) - This_Access works with calls from Collections/Array and WITH..ENDWITH
Just tried this with VFP 9.0 beta
o = CREATEOBJECT("myTest")
myCollection = CREATEOBJECT("collection")
LOCAL anArray (1)
anArray(1) = o
DEFINE CLASS myTest as Custom
? "ok with call: " + p_1
Contributors: wgcs, Doug Hennig, Bogdan Zamfir
Category VFP Commands Category Access And Assign
( Topic last updated: 2012.05.16 07:31:19 AM )