Read Structure from Data Section
Posted: Sun Sep 20, 2015 2:22 pm
If we want to read a structure from a data section, we currently have to do something like this:
This can obviously get very tiresome for larger structures. So how about allowing the following more intuitive way:
...I figured that it probably wouldn't work for "complex structures" (those including lists). So just allow it for structures of basic types. I'd say it would still be a great improvement.
Code: Select all
Structure MyStruc
String.s
Integer.i
Float.f
EndStructure
DataSection
MyData:
Data.i 2
Data.s "Text 1" : Data.i 12 : Data.f 3.4
Data.s "Text 2" : Data.i 56 : Data.f 7.8
EndDataSection
Define i, iMax, NewList Xs.MyStruc()
Restore MyData
Read.i iMax
For i = 1 To iMax
AddElement(Xs())
Read.s Xs()\String
Read.i Xs()\Integer
Read.f Xs()\Float
Next
Code: Select all
Structure MyStruc
String.s
Integer.i
Float.f
EndStructure
DataSection
MyData:
Data.i 2
Data.MyStruc "Text 1", 12, 3.4 ; If absolutely necessary the default way of storing would be ok too (see first example)
Data.MyStruc "Text 2", 56, 7.8
EndDataSection
Define i, iMax, NewList Xs.MyStruc()
Restore MyData
Read.i iMax
For i = 1 To iMax
AddElement(Xs())
Read.MyStruc Xs() ; Here is the magic!
Next