Little John wrote:
netmaestro wrote:
If you're willing to do a bit of work up front though, you can greatly simplify coding later by using offsets rather than names
Which is what I do now
Right now my approach is to translate the user input string into an offset value plus the type of the field for the memory peeking function. (in order to decide when to use PeekI or PeekS etc...)
Of course I could replace the Select ... Case ... Endselect section with a map that takes the string as key and returns the offset.
However, as with my current approach I would have to manually write new code for referencing the offset when I add new field to the structure and my main question is if it is possible in any kind if way to automatize this

As mentioned, the JSON (and XML) libraries can do exactly this, though I wonder if they use compiler directives that are not public.
For the sake of completeness, my above code can be implemented with maps like this:
Code:
Define NewMap off()
off("id") = OffsetOf(struc\id)
off("name") = OffsetOf(struc\name$)
off("value") = OffsetOf(struc\value)
off("other_stuff") = OffsetOf(struc\other_stuff$)
off("etc") = OffsetOf(struc\etc$)
;...
offset = off(name$)