Help required with packer related problem

Just starting out? Need help? Post your questions and find answers here.
chris_b
Enthusiast
Enthusiast
Posts: 103
Joined: Sun Apr 27, 2003 1:54 am

Help required with packer related problem

Post by chris_b »

here's my simple code to test writing some numbers to a file, packing the file, and then retrieving the numbers from the packed file:

Code: Select all

Dim array.l(8)

Debug("original values")

For f=1 To 8
array(f)=Random(1000)
Debug(array(f))
Next

CreateFile(0, "test")
UseFile(0)

For f=1 To 8
WriteLong(array(f))
Next
CloseFile(0)

CreatePack("test.packed")
AddPackFile("test")
ClosePack()

OpenPack("test.packed") 
memaddr=NextPackFile() 
ClosePack() 

Debug("retrieved values")

offset=0
For f=1 To 8
Debug(PeekL(memaddr+offset))
offset=offset+4
Next

End
But the first number retrieved with PeekL is wrong. Can anybody please explain why? am I doing something wrong?
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

ClosePak() free the memory allocated previously by all the pack commands. So do it only when it's done...
chris_b
Enthusiast
Enthusiast
Posts: 103
Joined: Sun Apr 27, 2003 1:54 am

Post by chris_b »

:oops: doh! (well, at least I didn't embarass myself by posting in the bug reports forum!)

Thanks Fred!
Post Reply