Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Collection object and not all of This
Message
From
04/10/2014 17:06:07
 
 
To
04/10/2014 14:21:18
Antonio Lopes (Online)
BookMARC
Coimbra, Portugal
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2003 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01608770
Message ID:
01608777
Views:
60
>Dear All
>
>I was working with a class that involved a Collection added at run time. I encountered a problem that I eventually managed to circumvent, but I would like to understand what was I doing wrong, if anything, with my original design.
>
>At first, I thought of a scope problem, but strangely I was able to access the Collection properties. What failed with me was that I couldn't (and cannot) access its items by any mean.
>
>I wrote a small program that reproduces my problem, with the help of the Debugger. If anyone is willing to give me a hand on this, I would ask to run the program and, when the debugger is launched and the program suspended, to insert the following watches (they are refered in the program so it will be easy to select each expression in the code and move it to the Watch field):
>
>This.Parameters.Count
>This.Parameters.GetKey(1)
>This.Parameters(m.lcKey)
>This.Parameters.Item(1)
>m.lnCount
>m.lcKey
>m.lnValueK
>m.lnValueN
>
>Afterwards, the program can be resumed a line at a time, and what I observed is that the variables got the expected values but all others watches could not be evaluated, with the exception of This.Parameters.Count that evaluated correctly to 3.
>
>My question is: what can explain this behavior of the items being inaccessible, athough the other properties of the Collection can be accessed - including the number of items in the Collection?
m.loObject = CREATEOBJECT("someClass")
m.loObject.SetParameter("id", 1)
m.loObject.SetParameter("model", "Model name")
m.loObject.SetParameter("description", "Model description")
m.loObject.someMethod()

DEFINE CLASS someClass as Custom

	Parameters = .NULL.

	FUNCTION SetParameter
		LPARAMETERS tcId, teValue

		IF ISNULL(This.Parameters)
			This.Parameters = CREATEOBJECT("Collection")
		ENDIF

		This.Parameters.Add(m.teValue, m.tcId)
	ENDFUNC

	FUNCTION someMethod

*!*			SET STEP ON
*!*			m.lnCount = This.Parameters.Count
*!*			m.lcKey = This.Parameters.GetKey(1)
*!*			m.lnValueK = This.Parameters(m.lcKey)
*!*			m.lnValueN = This.Parameters.Item(1)
*!*			m.lcDummy = "" && just to show the watches in the debugger
		
		CLEAR
		
		* Using FOR EACH
		FOR EACH luItem IN This.Parameters FOXOBJECT
			?luItem
                        * I don't know how to get the Key value of an luItem accessed this way
		
		ENDFOR
		
		?"--"
		
		* Using FOR
		FOR lnIx = 1 TO This.Parameters.Count STEP 1
			m.lcKey = This.Parameters.GetKey( lnIx )
			?m.lcKey
			?This.Parameters( m.lcKey )
		
		ENDFOR

	ENDFUNC

ENDDEFINE
With your original code I see the same thing. The Items of the collection don't show up in the Locals treeview under the "Parameters" collection.

I modified someMethod as above. The collection Items are now accessible as expected.

I wonder if this is an artifact of the debugger i.e. it can't display or access Collection Items (?)

I also wondered if using the keyword "Parameters" as the name of the collection was causing problems. I changed it to something else but that made no difference.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform