Wiki Home

This Access


Namespace: VFP

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 :
http://zbconsulting.dyndns.org/Articles/GlobalAccessandAssignEvents/tabid/57/Default.aspx

Streamline configuration by assigning global options with Access and Assign events
http://zbconsulting.dyndns.org/Articles/Streamlineconfigurationwith_Accessand_Assign/tabid/60/Default.aspx

(Updated on [2007.09.07 08:40:58 AM GMT] )
Bogdan Zamfir

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.Count and 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.
LOCAL obj
obj = create("test")

obj.Something()
? "---"
WITH obj
  .Something()
ENDWITH

DEFINE CLASS test AS CUSTOM

  PROCEDURE THIS_Access
  LPARAMETERS cMember
    ? "THIS_Access", cMember
    RETURN THIS
  ENDPROC

  PROCEDURE Something
    ? "Something"
  ENDPROC

ENDDEFINE


Something like
WITH obj.AnotherObj
   ...
ENDWITH

works

-(

Is the right Question "What should THIS_Access be used for?" or "Can THIS_Access really be used?"
-- Kurt

VFP 9.0 is cool :-) - This_Access works with calls from Collections/Array and WITH..ENDWITH
Just tried this with VFP 9.0 beta
CLEAR

o = CREATEOBJECT("myTest")

myCollection = CREATEOBJECT("collection")
myCollection.add(o, "theKey")
myCollection.item(1).mm_CallFromCollection()
myCollection.item("theKey").mm_CallFromCollection()
myCollection(1).mm_CallFromCollection()
myCollection("theKey").mm_CallFromCollection()

LOCAL anArray (1)
anArray(1) = o
anArray(1).mm_CallFromArray()

WITH o
  .mm_CallFromWith()
ENDWITH

DEFINE CLASS myTest as Custom

  PROCEDURE This_Access
    LPARAMETERS p_1
    ?
    ? "ok with call: " + p_1
    RETURN THIS
  ENDPROC

  PROCEDURE mm_CallFromCollection
    ? PROGRAM()
  ENDPROC

  PROCEDURE mm_CallFromArray
    ? PROGRAM()
  ENDPROC

  PROCEDURE mm_CallFromWith
    ? PROGRAM()
  ENDPROC
ENDDEFINE

-- Kurt
Contributors: wgcs, Doug Hennig, Bogdan Zamfir
Category VFP Commands Category Access And Assign
( Topic last updated: 2012.05.16 07:31:19 AM )