IsA Bug?

I think I may have a bug using IsA.
Please try this yourself.
The IsA line throws an type mismatch exception in the debugger, but clearly the object is a Xojo.Core.Dictionary according to the debugger.

[code]Function ToString(d as Xojo.Core.Dictionary, level as integer=0) As String
dim s as string=""
dim tabs as string=""
dim i as integer
dim entry as xojo.Core.DictionaryEntry

for i=0 to level-1
tabs = tabs + chr(9)

// Type Mismatch Exception Expected Object but got Int64
For Each entry In d
if entry.Value isa Xojo.Core.Dictionary then
s=s+ToString(entry.Value, level+1)
s = s + tabs + entry.Key + “=” + entry.Value + EndOfLine.UNIX
end if

return s
End Function[/code]

I can only reproduce your results if entry.Value contains something other than an object, for example, an Auto().

Try it this way instead:

if Xojo.Introspection.GetType( entry.Value ) = GetTypeInfo( Xojo.Core.Dictionary ) then...

BTW, it looks like you are using level only for your tabs, so consider passing in the tabs directly:

s = s + ToString( entry.Value, tabs + Chr( 9 ) )

Also, if your Dictionary is very big, I’d expect this to get very slow. You’re better off building a string array that you can join at the end of the process.

How do I know if Value can be expressed as a string?
Must I handle every data type?
right now the s = s + tabs + entry.Key + “=” + entry.Value + EndOfLine.UNIX is throwing an exception because Value isn’t a string.

Yes. At least for every data type you expect to possibly be in there. Then add an Else clause and raise an exception.

Do use try/catch because int, text, string etc are not objects and may be in the entry.value.

IsA is used for objects only.

You have isNumeric, don’t you ?