Dynamic Arrays In Structures?

Just starting out? Need help? Post your questions and find answers here.
lkd85
New User
New User
Posts: 4
Joined: Sun Dec 28, 2003 6:32 pm

Dynamic Arrays In Structures?

Post by lkd85 »

Hi again, I have yet another array question. I just saw an example of
how to fake dynamic arrays in Pure Basic. After this I modified it to see if it would work in the following way:

Code: Select all

Procedure CopyArray(PtrToSrcArray.l, PtrToDestArray.l, length.l)
  Dim getarraydata.b(length)
  
  CopyMemory(PtrToSrcArray,@getarraydata(),length)
  
  CopyMemory(@getarraydata(),PtrToDestArray,length)
  
EndProcedure

;------------------------------------------------------------------------------------#nullstring = ""

Structure names
  *name1.b[10]
EndStructure

Structure test
  number.l
  *names.names[0]
EndStructure
Dim *a.test(5)
Dim *b.test(5)

For i = 0 To 5
  *a(i) = GlobalAlloc_(#GMEM_FIXED|#GMEM_ZEROINIT, SizeOf(test))
  *b(i) = GlobalAlloc_(#GMEM_FIXED|#GMEM_ZEROINIT, SizeOf(test))
Next

For i = 0 To 5
  *a(i)\names = GlobalAlloc_(#GMEM_FIXED|#GMEM_ZEROINIT, SizeOf(names)*5)
  ;*a(i)\names\name1 = GlobalAlloc_(#GMEM_FIXED|#GMEM_ZEROINIT, 10)
  *b(i)\names = GlobalAlloc_(#GMEM_FIXED|#GMEM_ZEROINIT, SizeOf(names)*5)
  ;*b(i)\names\name1 = GlobalAlloc_(#GMEM_FIXED|#GMEM_ZEROINIT, 10)
Next

PokeS(@*a(0)\names[0]\name1,"Testing")
PokeS(@*a(1)\names[1]\name1,"Copying")
PokeS(@*a(2)\names[2]\name1,"Arrays")
PokeS(@*a(3)\names[3]\name1,"In")
PokeS(@*a(4)\names[4]\name1,"Pure")
PokeS(@*a(5)\names[5]\name1,"Basic")

Debug "Array A Has: "

For i = 0 To 5
  Debug PeekS(@*a(i)\names[i]\name1)
Next

Debug ""

Debug "Array B Has: "

For i = 0 To 5
  If PeekS(@*b(i)\names[i]\name1) = #nullstring  
   Debug "Nothing"
  Else 
    Debug PeekS(@*b(i)\names[i]\name1)
  EndIf  
Next

Debug ""

Debug "Now Array B Has: "

CopyArray(@*a(),@*b(),SizeOfArray(@*a()))

For i = 0 To 5
  Debug PeekS(@*b(i)\names[i]\name1)
Next
Does anyone know what i'm doing wrong. Thanks.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

you do lots of bad done things there.
Have you see it yet?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply