Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Bug? Calling methods in object returned by access method
Message
From
21/02/2003 01:45:24
Eric Barnett
Barnett Solutions Group, Inc
Sonoma, California, United States
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00755131
Message ID:
00755954
Views:
14
Uh oh, I think this is a bug, I have encountered the exact same problem, from a message I posted #753086:
-----------------------------
#2 For Access methods, the parameter value does not seem to be getting passed to the Access method, for example:

Class bizobjects has a property dataobjects[1,0]
----
Dataobjects_access method:
LPARAMETERS m.nIndex1
LOCAL nDataObject
....
RETURN this.dataobjects(m.nIndex1)
-----
When Executing line of code:

this.dataobjects(nCounter).setUtilityObject(this.oUtilityObject)

m.nIndex1 in the Access method is always .F.

This works fine in VFP6 & VFP7, I know we now have proper Collections (which the above code is designed to emulate, allows for named Collections like this.dataobjects("mydataobject").myProperty - but is this now going to be broken in VFP8 or is there a bug here or problem with my installation?
-----------------------------
This is going to be a big problem for me, as I do this EVERYWHERE and huge amounts of my code will break & I will have to rewrite everything to use Collections...

Eric


>Hi Cameron,
>
>thanks for your fast reply on the issue!
>
>>Forgive me if I am missing something but I don't see why much of this code should work at all.
>
>No problem, I will try to clarify what I'm doing. It's not just a theoretical example, it's a real world one. Maybe the code was a little confusing. The basic idea is to have a reference to a collection object stored in another collection and directly call a method of the inner collection.
>
>
>*-- With VFP8's native collection class it would look like so:
>
>loCollection = CREATEOBJECT("Collection")
>loCollRefToBeStoredInCollection = CREATEOBJECT("Collection")
>
>loCollection.Add(loCollRefToBeStoredInCollection)
>
>*-- Here we are adding an item to the collection object of which
>*-- a reference is stored in the first item of loCollection
>loCollection.Item(1).Add("Some value")
>
>
>The following code demonstrates for what I really use the assign method. It's simply a wrapper for the internal array. I ask for an array property (Items) value and simply return an array item from the internal array. Since the returned array element is an object reference, I can directly call methods in the returned object just like I would be able to call an object's methods when it is stored in a public array property without an assign method. I hope I was able to describe this properly, so you can follow the thoughts behind the code.
>
>
>*--------------------------------------------------------------
>*--
>*-- Visual FoxPro 08.00.0000.2521 for Windows
>*--
>*-- Works fine in Visual FoxPro 07.00.0000.9465 for Windows
>*--
>*-- Demonstrates possible access method bug when directly
>*-- calling a method in the returned object like so:
>*--
>*-- THIS.uProp(1).Add("1")
>*--
>*-- The access method gets .F. instead of 1 as it's
>*-- parameter value. For workarounds see below.
>*--
>*-- Submitted by armin.neudert@ansta.de
>*-- 02-19-2003 08:50 pm
>*-- Version 2
>*--------------------------------------------------------------
>
>LOCAL loCollection, loCollRefToBeStoredInCollection
>
>loCollection = CREATEOBJECT("myCollection")
>loCollRefToBeStoredInCollection = CREATEOBJECT("myCollection")
>
>loCollection.Add(loCollRefToBeStoredInCollection)
>
>*-- Here we are adding an item to the collection object of which
>*-- a reference is stored in the first item of loCollection
>
>*-- Error in VFP8!
>loCollection.Item(1).Add("Some value")
>
>*-- No error!
>LOCAL loTemp
>loTemp = loCollection.Item(1)
>loTemp.Add("Some value")
>
>RETURN
>
>
>
>DEFINE CLASS myCollection AS Session
>
>	*-- This array is only there so we can have
>	*-- an access method we can use to wrap
>	*-- access to the internal array
>	DIMENSION Item[1]
>	
>	*-- This array is the internal one that
>	*-- holds our items. No direct access
>	*-- from the outside allowed (encapsulation!)
>	PROTECTED aItems[1]
>
>	PROCEDURE Add
>		LPARAMETERS tluItem
>		
>		IF THIS.aItems[1] <> .F.
>			DIMENSION THIS.aItems[THIS.ALEN(aItems)+1]
>		ENDIF
>		
>		THIS.aItems[ALEN(THIS.aItems)] = tluItem
>
>	ENDPROC
>
>	PROCEDURE Item_Access
>		LPARAMETERS tlnIndex
>
>		MESSAGEBOX( "Index passed to access method: " + TRANSFORM(tlnIndex) )
>		
>		RETURN THIS.aItems[tlnIndex]
>	
>	ENDPROC
>
>ENDDEFINE
>
>
>
>>Are you using a documented feature that I am not aware or is this code taking advantage of an anomaly in VFP?
>
>IMO it's an absolutely "legal" way of using access methods. There should be some more people out there doing this the same way ...
>
>Regards,
>Armin
Eric Shaneson
Cutting Edge Consulting
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform