Array of text strings, how to ??
RogerInHawaii
Posts: 87
I'm trying to construct an array of text strings in Spin. Since that doesn't seem to be directly possible I've taken the approach of declaring the strings separately and then having an array of pointers to those strings. Here's my code:
When I look at the code using the Object Info window the MenuItems reside at the following positions (in Hex):
When I run the program I write out some diagnostic information to the Parallax Serial Terminal. The MenuMain (which is my array of pointers to the various MenuItemStrings) happens to reside at location 83 (hex). Looking at the set of consecutive values that reside there I see that it thinks that the menu item strings start at the following positions:
That is, each string pointer is pointing at the wrong location. I seems that each pointer value is exactly 10 Hex less than it should be. And, indeed, when I try to access the strings via the pointers contained within the MenuMain array I get only partial strings, because the pointers are not pointing at te correct starting character for each string.
How do I get this to work as I desire?
DAT MenuItemQueryMode byte "Query Mode", 0 MenuItemFreeRunning byte "Free Running", 0 MenuItemSnapshot byte "Snapshot", 0 MenuItemCalibrate byte "Calibrate", 0 MenuMain word @MenuItemQueryMode, @MenuItemFreeRunning, @MenuItemSnapshot, @MenuItemCalibrate, 0
When I look at the code using the Object Info window the MenuItems reside at the following positions (in Hex):
MenuItemQueryMode 28 MenuItemFreeRunning 33 MenuItemSnapshot 40 MenuItemCalibrate 49
When I run the program I write out some diagnostic information to the Parallax Serial Terminal. The MenuMain (which is my array of pointers to the various MenuItemStrings) happens to reside at location 83 (hex). Looking at the set of consecutive values that reside there I see that it thinks that the menu item strings start at the following positions:
MenuItemQueryMode 18 MenuItemFreeRunning 23 MenuItemSnapshot 30 MenuItemCalibrate 39
That is, each string pointer is pointing at the wrong location. I seems that each pointer value is exactly 10 Hex less than it should be. And, indeed, when I try to access the strings via the pointers contained within the MenuMain array I get only partial strings, because the pointers are not pointing at te correct starting character for each string.
How do I get this to work as I desire?
Comments
And that works fine. There should be the number 3 in square brackets after the @@MenuMain, but it doesn't seem to show up in code mode. (VideoScreen.WriteText is my modified version of the FullDuplexSerialPlus object)
But I have a complication. My intention is to pass MenuMain (i.e. the address of it) to a function which then uses it to index through its elements, getting the address of each of its strings, and use those strings.
But if I pass the address of MenuMain, as in:
when it gets into the Show method all it knows is the absolute address of the object. It doesn't know the object itself.
What do I do when I pass in something like MenuMain to a method? How do I get it to calculate the correct addresses?
So the @ symbol isn't right, and neither apparently is the @@ symbol.
This will change all the addresses to absolute addresses rather than offsets from the start of the object's data area.
The rest of your program can use the corrected addresses.
- Roger