Say your photos are: "A,B,C,D,E,F,G"
The index is at 0.
You call getNext() to move the index to 1.
The value at position 1 is "A."
You delete "A."
You've reached the end of the loop. The list is now "B,C,D,E,F,G."
You call hasNext(), which is true.
You call getNext() to move the index to 2.
The value at position 2 is "C."
You delete "C," your list is now "B,D,E,F,G," you call getNext() to
move to position 3, where you find "E," etc.
Make sense? I don't know for sure that's what's happening but this
type of bug has bitten me many times.
Patrick
On 11/27/06, Dan Sorensen <[EMAIL PROTECTED]> wrote:
When I run the following .hasMore() / .getNext() loop, it will end up
skipping every other record. If I specify to delete 1,2,3,4 as the example
shows, it will only delete 1 & 3. This makes me believe that I'm somehow
triggering .getNext() twice during each loop. Is there a better way to
access the record attributes returned from Iterator.getNext() without
advancing to the next record until I loop around again?
Sample Code:
<cfparam name="FORM.photosToDelete" default="1,2,3,4"> <!--- Delete photos 1
through 4 --->
<cfset photos = article.getPhotoIterator()>
<!--- Assume that photo records 1 through 4 are the only ones associated
with this article record through the Iterator and are returned with full
attributes --->
<cfloop condition="photos.hasMore() IS TRUE">
<cfset thisPhoto = photos.getNext()>
<cfif listContains(FORM.photosToDelete, thisPhoto.getID())>
<cffile action="delete"
file="#thisPhoto.getPath()#">
<cffile action="delete"
file="#thisPhoto.getThumbnailPath()#">
<cfset thisPhoto.delete()>
</cfif>
</cfloop>
I've read through the Iterator source code, and the Iterator example at
(http://www.doughughes.net/index.cfm?event=viewEntry&entryId=199),
but I'm still learning. Please let me know if you see my error or have a
better solution.
Thank for any suggestions,
Dan
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
Reactor for ColdFusion Mailing List
[email protected]
Archives at:
http://www.mail-archive.com/reactor%40doughughes.net/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
--
Patrick McElhaney
704.560.9117
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Reactor for ColdFusion Mailing List
[email protected]
Archives at: http://www.mail-archive.com/reactor%40doughughes.net/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --