Code: Select all
Define box1.RECT
box1\left=1
box1\top=2
box1\right=3
box1\bottom=4
mem=AllocateMemory(SizeOf(RECT))
CopyMemory(@box1.RECT,mem,SizeOf(RECT))
*box2.RECT=mem
Debug *box2\left
Debug *box2\top
Debug *box2\right
Debug *box2\bottom
Code: Select all
Define box1.RECT
box1\left=1
box1\top=2
box1\right=3
box1\bottom=4
mem=AllocateMemory(SizeOf(RECT))
CopyMemory(@box1.RECT,mem,SizeOf(RECT))
*box2.RECT=mem
Debug *box2\left
Debug *box2\top
Debug *box2\right
Debug *box2\bottom
Code: Select all
Structure ARECT
left.l
top.l
right.l
bottom.l
string.s{6}
EndStructure
Define box1.ARECT
box1\left=1
box1\top=2
box1\right=3
box1\bottom=4
box1\string="Hello!"
mem=AllocateMemory(SizeOf(ARECT))
CopyMemory(@box1.ARECT,mem,SizeOf(ARECT))
*box2.ARECT=mem
Debug *box2\left
Debug *box2\top
Debug *box2\right
Debug *box2\bottom
Debug *box2\string
Copying a structure containing strings to one created dynamically with AllocateMemory() requires that you take steps to free the copies when the memory is released as Purebasic will not do this for you. Still, it's easy enough.Joakim Christiansen wrote:That's why we need you to make a function that works with strings tooFred wrote:Just ensure there is no string in your structure, or you will run into problems.
Should not be:Fred wrote:Just ensure there is no string in your structure, or you will run into problems.
Just ensure there is no string in your structure, or you could run into problems.
Code: Select all
Structure ARECT
left.l
top.l
right.l
bottom.l
string.s{6}
another$
another.s
anotherone$
EndStructure
Define box1.ARECT
box1\left=1
box1\top=2
box1\right=3
box1\bottom=4
box1\string="Hello!"
box1\another$="Hellooo!"
box1\another="Helloooooooo!.s"
box1\anotherone$="Hiiiiiiiiooooooo!"
*box2.ARECT=AllocateMemory(SizeOf(ARECT))
CopyMemory(@box1.ARECT,*box2.ARECT,SizeOf(ARECT))
Debug *box2\left
Debug *box2\top
Debug *box2\right
Debug *box2\bottom
Debug *box2\string
Debug *box2\another$
Debug *box2\another
Debug *box2\anotherone$
Code: Select all
Structure ARECT
left.l
top.l
right.l
bottom.l
string.s{6}
another$
another.s
anotherone$
EndStructure
Define box1.ARECT
box1\left=1
box1\top=2
box1\right=3
box1\bottom=4
box1\string="Hello!"
box1\another$="Hellooo!"
box1\another="Helloooooooo!.s"
box1\anotherone$="Hiiiiiiiiooooooo!"
*box2.ARECT=AllocateMemory(SizeOf(ARECT))
CopyMemory(@box1.ARECT,*box2.ARECT,SizeOf(ARECT))
box1\another$="OYdddddddddddddddddddddddddddddddddddddddddddddddddd!"
Debug *box2\another$
Code: Select all
box1\another$="OYdddddddddddddddddddddddddddddddddddddddddddddddddd!"