New instance

Just starting out? Need help? Post your questions and find answers here.
Phollyer
User
User
Posts: 90
Joined: Sat Jun 03, 2017 3:36 am
Location: USA, Texas
Contact:

New instance

Post by Phollyer »

I have a List of a Structure

I'm looping through the a folder collecting specific types of files
when I have multiple records to collect in a single folder the code is not generating a New instance of my structure...its writing over the First Instance
Below is pseudo of what I am doing

my List (or collection) is WorkMonster\AnimationCollection()
.Animations is my Structure containing
\TypeID
\Graphic

Code: Select all

If ExamineDirectory(0, MPATH$, "*.png")  
  While NextDirectoryEntry(0) 
    LoadImage(#imgSrcImage, MPATH$+FileName$, 0)
    If FindString(LCase(DirectoryEntryName(4)), "walk") > 0
      Move = 1
    endif
    If FindString(LCase(DirectoryEntryName(4)), "run") > 0
      Move = 1
    endif

    switch Move
      case 1
	WorkFacAnimation.Animations
	WorkFacAnimation\TypeID = #Movement
	FreeImage(WorkFacAnimation\Graphic)
	WorkFacAnimation\Graphic = CopyImage(#imgSrcImage, #PB_Any)
	AddElement(WorkMonster\AnimationCollection())
	WorkMonster\AnimationCollection() = WorkFacAnimation 
    endswitch

  wend
endif
in a C# world I would enter
Animations WorkFacAnimation = new Animations()

this forces a new instance of the class or structure

how do I force this NEW concept?
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: New instance

Post by Josh »

Code: Select all

*WorkFacAnimation.Animations = AllocateMemory (SizeOf (Animations))
or add the pointer directly to your collection. Don't forget to free your allocated spaces in this case.

On the other hand, why you are not writing directly in the list?
sorry for my bad english
Phollyer
User
User
Posts: 90
Joined: Sat Jun 03, 2017 3:36 am
Location: USA, Texas
Contact:

Re: New instance

Post by Phollyer »

I Apologize for late reply....
I figured out a solution about an hour after I posted that...I then (thought) I had deleted this question....

to answer your question I always load screens from objects (and their child collections)...which allows for users to hit cancel undoing all changes...
in this case it was loading a child collection of images...

pete
Post Reply