I'm trying to extend this GNU-licensed plugin MI2SVG, which converts MapInfo maps to SVG, so that it writes associated table data into the SVG it creates, so that browser based JS web applications can read map data from MapInfo-created interactive maps.
It's going well except I can't find the MapBasic way to loop through all columns for one row in a layer, in a way that gives the index (column name or name) in each iteration alongside the data.
The only MapBasic loop examples I can find are for looping through table rows using the very specific Do While Not EOT()
, which seems to be always used for rows and doesn't appear to give each iteration's index (or if it does, I can't see where).
So for example, here's code that loops through rows in a layer table i.e. features in a map and prints the contents of column 1 into a string:
sLayer = LayerInfo (nMap, nLayer, LAYER_INFO_NAME)
'Initialize alias variables
aObj = sLayer + ".obj"
aRow = sLayer + ".rowid"
aCol = sLayer + ".col1"
'Convert each feature in the layer to SVG
Fetch First From sLayer
Do While Not EOT(sLayer)
objA = aObj
nRow = aRow
sCol = aCol
'some code that prints SVG like "<path name="""&sCol&...etc
How would you loop through all the columns, getting index and values for each? My ideal output would be, instead of name="""&sCol&"""
a string like this: data-col1="[col1data]" data-col2="[col2data]" data-col3="[col3data]"
for tables with any number of columns, printing the index (name or number) and value concatenated with some other text for each column.
I'm guessing it would be something like this (but with ???
s replaced with actual things I can't find in the MapBasic reference and User Guide):
Fetch First From sLayer
Do While Not EOT(sLayer)
objRow = aObj
sOutput = ""
Fetch First From objRow
Do While Not ???(objRow)
sColumnName = ????Info ( someArgs?, ????_????_NAME )
nColumnIndex = ?increment???
'Not sure what type for this variable since data could be string or numeric?
?ColumnData = objRow.col(nColumnIndex)
outputString = outputString & " data-"&sColumnName&"="""&?ColumnData&"""
...or maybe instead of Do While Not ???(objRow)
a for..next loop :
nColumnCount = objRow.???NumberOfColumns??? 'or' TableInfo( nLayer??, TAB_INFO_NCOLS )
for nCounter 1 To nColumnCount
sColumnName = ????Info ( someArgs?, ????_????_NAME )
?ColumnData = objRow.col(nColumnIndex)
'some code that prints SVG like "<path name="""&sCol&...etc
next
...but despite wading through the MapBasic reference, user guide and trying to fill in the gaps with http://testdrive.mapinfo.com/ I can't find what to use to fill those blanks.