Pointer in a Structure

Everything else that doesn't fall into one of the other PB categories.
Killswitch
Enthusiast
Enthusiast
Posts: 731
Joined: Wed Apr 21, 2004 7:12 pm

Pointer in a Structure

Post by Killswitch »

What I would like to do is have a pointer in a structure so I can read a file in a pack then later write that data. This is what i've tried:

Code: Select all

Structure a
*a
b.l
endstructure

dim defile.a(10)

defile\a=nextpackfile()
defile\b=packfilesize()

createfile(0,"bob.txt")
   writedata(defile\a,defile\b)
closefile(0)

Thats not my code exactly, but it is what I've been trying to do. When I try to write the data to a file PB says that the pointer is null. Is there a way around this, or is it just not posible?
~I see one problem with your reasoning: the fact is thats not a chicken~
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post by freedimension »

I've been using this

Code: Select all

Structure ByteArray
  b.b[0]
EndStructure
Structure Data
  *data.ByteArray
EndStructure


*x.Data = AllocateMemory(100)
*x\data\b[0] = 0
Killswitch
Enthusiast
Enthusiast
Posts: 731
Joined: Wed Apr 21, 2004 7:12 pm

Post by Killswitch »

Thank ye very much!
~I see one problem with your reasoning: the fact is thats not a chicken~
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post by freedimension »

This way you can adress every single Byte directly using the static-Array [x] Syntax. Very usefull.
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

killswhich,

In you original solution you dim defile as an array, then access it as a variable.

defile\a when it should be defile(1)\a.
Killswitch
Enthusiast
Enthusiast
Posts: 731
Joined: Wed Apr 21, 2004 7:12 pm

Post by Killswitch »

Thanks, I have been doing that with my code but the real stuff is upstairs on my internet-free 98 box, you won't believe the amount of problems that mistake has caused me though!
~I see one problem with your reasoning: the fact is thats not a chicken~
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

~I see one problem with your code: the fact is thats not a array~
Post Reply