Page 1 of 1
SaveStructure(), LoadStructure(), CatchStructure()
Posted: Thu Jun 03, 2010 7:07 pm
by Seymour Clufley
Code: Select all
SaveStructure(@st,StructureType,filename$)
LoadStructure(@st,StructureType,filename$)
CatchStructure(@st,StructureType,*mem)
I realise this would be a lot of work - need to accommodate maps, lists, arrays, static arrays etc. - but it would be very useful indeed!
It would require delimiting many different things - where an array begins, where each item in the array ends etc. Perhaps some kind of file structure could be made for handling PB structures, maybe XML-based.
Of course we all write our own code for filling a structure from a file, but a universal function to do it for any structure type would cut a lot of code-writing for users. Universal functions like this are the kind of thing us users
can't do!
If support for multidimensional arrays is going to be added in future, it may be best to wait until then.
Re: SaveStructure(), LoadStructure(), CatchStructure()
Posted: Fri Jun 04, 2010 2:27 pm
by Justin
I use these functions to save small structures in xml files, mostly settings files. It needs some more error checking.
Code: Select all
procedure.s peekHEX(mem.i, bytes.i)
define.s st, h
define.i x
define.b vs
define.w vu
for x=0 to bytes-1
vs.b=peekb(mem+x)
vu.w = vs & $FF
h=hex(vu)
if len(h)=1 : h="0" + h : endif
st=st + h
next
procedurereturn st
endprocedure
procedure ReadHEX(hexSt.s, *mem.BYTE, memSize.i)
define.i pos, bRead
define.s sbyte
bRead = 0
pos=1
sbyte = mid(hexSt, pos, 2)
while sbyte and bRead<=memSize
*mem\b = val("$" + sbyte)
pos + 2
*mem + sizeof(BYTE)
sbyte = mid(hexSt, pos, 2)
bRead + 1
wend
endprocedure
define.POINT pt, pt2
define.s txt
pt\x = 10
pt\y = 20
txt = peekHEX(@pt, sizeof(POINT))
debug txt
ReadHEX(txt, @pt2, sizeof(POINT))
debug pt2\x
debug pt2\y
Re: SaveStructure(), LoadStructure(), CatchStructure()
Posted: Fri Jun 04, 2010 3:44 pm
by STARGÅTE
SaveStructure(), LoadStructure(), CatchStructure() ar not good !
Its better to have:
WriteStructure(FileNumber, *Buffer, StructureName)
ReadStructure(FileNumber, *Buffer, StructureName)
i have same Includes for this one, but a nativ function in PB is verry good

Re: SaveStructure(), LoadStructure(), CatchStructure()
Posted: Fri Jun 04, 2010 5:02 pm
by Seymour Clufley
STARGÅTE wrote:Its better to have:
WriteStructure(FileNumber, *Buffer, StructureName)
ReadStructure(FileNumber, *Buffer, StructureName)
File numbers instead of names? But how could it be safely read back in, then, if you had saved other data in the file? Save/LoadImage couldn't work like that.