dim s as string = "hi"
dim d as new Xojo.Core.Dictionary
d.Value( "a" ) = s
dim a as Auto = d.Value( "a" )
dim ti as Xojo.Introspection.TypeInfo = Xojo.Introspection.GetType( a )
MsgBox ti.Name
I’m using all Xojo.Core.Dictionary though. So it should be OK.
If I do this:
Dim hres As String = d.Value("HRES")
Dim vres As String = d.Value("VRES")
Dim s as string = hres+"x"+vres
It works just fine. But somehow when using the expression to pull the values from the dictionary, Xojo is expecting everything to be Text. That seems like a Bug.
I know I had an issue a year(?) ago with using string literals with Xojo.Core.Dictionary but I believe it was fixed rather quickly. What version of Xojo are you using?
[quote=322135:@Kem Tekinay]I can’t reproduce this. I used this as test code.
dim s as string = "hi"
dim d as new Xojo.Core.Dictionary
d.Value( "a" ) = s
dim a as Auto = d.Value( "a" )
dim ti as Xojo.Introspection.TypeInfo = Xojo.Introspection.GetType( a )
MsgBox ti.Name
I get String.[/quote]
Kem,
Try this:
Sub Open()
Dim s1 As String = "Hi"
Dim s2 As String = "There"
Dim d As New Xojo.Core.Dictionary
d.value("a") = s1
d.value("b") = s2
Dim s3 As String = d.value("a")+" "+d.value("b")
MsgBox s3
End Sub
It’s the expression of concatenating the two dictionary values where it gets hosed.
Now, I’m assuming that since a dictionary stores Autos and since Autos are supposed to give back the same type you put in, that this concatenation should work - but it doesn’t.
[code] Dim rg As New RegEx
Dim match As RegExMatch
dim sval as string = “1 2 3 4 5 6 7”
rg.SearchPattern="(\\d+) (\\d+) (\\d+) (\\d+) (\\d+) (\\d+) (\\d+)"
match=rg.Search(sval)
if match<>nil then
Dim d As New Xojo.Core.Dictionary
d.Value("HRES") = match.SubExpressionString(1)
d.Value("VRES") = match.SubExpressionString(2)
d.Value("FrameRate") = match.SubExpressionString(3)
d.Value("Format") = match.SubExpressionString(4)
d.Value("AspectRatio") = match.SubExpressionString(5)
d.Value("ColorDepth") = match.SubExpressionString(6)
Dim s as String = d.Value("HRES")+"x"+d.Value("VRES")
break
end if[/code]
[quote=322147:@Paul Lefebvre]It looks like the literal (“x”) is confusing the expression.
You can see the same thing here:
Dim s1 As String = "test"
Dim a As Auto = s1
Dim s2 As String = a + "x"[/quote]
It is but that seems like a bug in the framework which is due to this tremendously confusing overlay of strings and text. I understand why you guy developed the Text type but it’s a mess.
Dim s1 as string = "bo"
Dim s2 as string = "top"
Dim s3 as string = s1+"x"+s2
Will work fine. “x” here is seen as a string value.
Since Auto is supposed to give back what you put in, why is the framework expecting it to be text?
OK. The plot thickens! I discovered that this does not work:
Sub Open()
Dim s1 As String = "Hi "
Dim s2 As String = "There"
Dim d As New Xojo.Core.Dictionary
d.value("a") = s1
d.value("b") = s2
Dim s3 As String = d.value("a")+d.value("b")
MsgBox s3
End Sub
Apparently Auto does not have the “+” operator. So the framework is assuming that +" "+ here is text not string. It’s the “+” operator that is screwing things up. Xojo does not check to see what is stored in the auto before doing operations on it. You have to extract it first or perhaps use Ctype.
Auto makes far fewer assumptions than Variant. This is inconvenient in some respects but also safer. You have to be explicit about what you want.
A literal can be either a String or Text depending on context and your usage is making the context unclear, I guess. But if you’re using String anyway, can you also use the faster classic Dictionary where you can specify Value().StringValue?
That is sensitive to encoding issues unlike the new dictionary
Pick yer poison
In this code the second addition of “abc” works in the old dictionary simply because the encoding is different
In the new dictionary it doesn’t add "abc"again and compares string keys with different encodings correctly
dim OldDict as new dictionary
dim NewDict as new xojo.Core.Dictionary
dim s as string
s = "abc"
s = ConvertEncoding(s, Encodings.ASCII)
if OldDict.HasKey(s) = false then
OldDict.value(s) = s
end if
if NewDict.HasKey(s) = false then
NewDict.value(s) = s
end if
s = "abc"
s = ConvertEncoding(s, Encodings.UTF16)
if OldDict.HasKey(s) = false then
OldDict.value(s) = s
end if
if NewDict.HasKey(s) = false then
NewDict.value(s) = s
end if
break