« Microsoft or Disneyland? | Main | Finding the Perfect Coach »
August 09, 2005
Debugging a collection in VFP
Have you ever been stepping through some VFP code that uses a collection and been frustrated that you can't "see" into the collection? Well if you have, here's a program that I found somewhere in Microsoft's information (but don't remember where, could have been a website or blog).
Basically this adds an array property to the collection that contains the items in the collection. It even handles a collection that contains other collections.
To use it just drop out to the command window and invoke it with DebugCollection(loCollection) and then go back to the Locals or Watch window of the debugger and look through the Items array using the normal + that shows up for an array.
Name the PRG DebugCollection.prg.
*PROCEDURE DebugCollection(oCollection)
LPARAMETERS oCollection
IF oCollection.COUNT=0
RETURN
ENDIF
oCollection.ADDPROPERTY("Items[1]")
DIMENSION oCollection.Items[oCollection.Count]
FOR i = 1 TO oCollection.COUNT
oCollection.Items[m.i]=oCollection.ITEM[m.i]
IF VARTYPE(oCollection.ITEM[m.i])="O" ;
AND VARTYPE(oCollection.ITEM[m.i].BASECLASS)="C" ;
AND oCollection.ITEM[m.i].BASECLASS="Collection"
IF oCollection=oCollection.ITEM[m.i]
LOOP
ENDIF
DebugCollection(oCollection.ITEM[m.i])
ENDIF
ENDFOR
*ENDPROC
Posted by Glenn Taylor on August 9, 2005 | Permalink
TrackBack
TrackBack URL for this entry:
http://www.typepad.com/t/trackback/384091/2974501
Listed below are links to weblogs that reference Debugging a collection in VFP:
Comments
In the Watch window, you can add an entry like loCollection[1]. This will use the 'Default' Item method for retrieving the value stored in the collection.
So the code you've passed isn't really nessacery ;)
Sietse
Posted by: Setse Wijnker | Aug 10, 2005 12:24:01 AM




