Need help

BlitzMax Forums/BlitzMax Programming/Need help

MacSven(Posted 2012) [#1]
i have a Type.
in it is the Field:

	Field sKeywords:String[] = ["body","doctype","head","html","meta","address","blockquote","br","div","em","h1","h2","h3","h4","h5","h6","p","pre","strong","sub","sup","b","big","hr","i","small","tt","dd","dl","dt","li","ol","ul","a","caption","table","td","th","tr","frame","frameset","iframe","noframes","img","map","object","style","button","form","input","label","legend","option","select","textarea","script","noscript"]


I have now a list with new words in a tlist.
Can i use the Field with the tlist

listtoarray does not work here.


col(Posted 2012) [#2]
Hiya,

ListToArray will return the result as

Object[]

which is an array of objects, so you need to cast them to strings as

*instance*.sKeywords = String[]( ListToArray(*YourTList*) )

replace *instance* and *YourTList* as needed with your variables.


EDIT :- OMG! That should work but it doesnt! I'd say that is a bug for sure, unless I'm missing something within the cast?

You can do it manually :-

Replace ListToArray with this function:-
Function StringListToArray$[](InList:TList)
	Local StringArray$[]
	Local Count
	
	StringArray = StringArray[..InList.Count()]
	For Str$ = EachIn InList
		StringArray[Count] = Str
		Count:+1
	Next
	
	Return StringArray
EndFunction



EDIT2:-

Another alternative would be to use

Field sKeywords:Object[] = [.....]

then use

*instance*.sKeywords = ListToArray( YourTList )
Print String (*instance*.sKeywords[ Index ] )

Don't know why the String[] cast isn't working though.

Last edited 2012