Having trouble with adding images to TList?

BlitzMax Forums/BlitzMax Programming/Having trouble with adding images to TList?

JoJo(Posted 2008) [#1]
I'm trying to write a procedure that goes thru a directory and grab the name and extension of the pictures in the directory.

The program will cycle through the images every few seconds much like a slide show.

The problem I'm having is that when the object is getting added to the list, it keeps adding the last image.
So when I run the program the last images is just showing.

Global picsTList:TList = New TList
LoadImages() 

For Local p:TMyPictures = EachIn picsTList
	Cls
	DrawImage(p.pics, 0, 0, 0) 
	Flip
        Delay(2000)
Next

Function LoadImages:TImage () 
	'load images from dir
	Local files:String[] 
	Local t:TMyPictures = New TMyPictures
	files = LoadDir("images") 
	' load images in array
	For Local str:String = EachIn files
		t.pics = LoadImage("images\" + str) 
		t.picPath = "images\" + str
		picsTList.AddLast(t) 
	Next
End Function

Type TMyPictures
	Field pics:TImage
	Field picPath:String
End Type




GfK(Posted 2008) [#2]
Need to put t:TMyPictures = New TMyPictures before t.pics=LoadImage....

The way you're doing it, you're creating another instance of the existing TImage in the TList, rather than making a new copy of it. You've basically ended up with a bunch of pointers referencing the same data (the last image you loaded).


JoJo(Posted 2008) [#3]
Thanks!
I can't believe I did that.