Inspecting variant data

Got a strange bug with High Sierra/Xojo 2017r1. In my app you can select a mail client and the get/set data for said mail client. In the preferences I save a dictionary where the keys are the mail clients like Mail, Outlook etc.

[code]EmailClientDictionary = globals.thePrefs.GetPrefDictionary(“EmailInfo_MailApps”)

if EmailClientDictionary.HasKey(MailApplication) then <---- fail here
'get the data for the mail client
end if[/code]

The check with HasKey is failing. I’ve had one customer send me his plist file and the dictionary is there and it has the correct value.

So to my question: I can get the keys with

dim MailClients(-1) as Variant = EmailClientDictionary.Keys

and then convert to string. But can I get the raw data for the dictionary keys? With values like Mail and Outlook it’s unlikely that the problem is an encoding problem. But I’d rather be sure.

What das failing mean? Crash? Runtime exception?

All incoming strings need DefineEncoding “on arrival”. All. Once is not enough: All. Twice is not enough: All.

Remark for a big fan of the old framework: with Auto instead of Variant and Text instead of String this probably would not even compile…

HasKey fails even if the dictionary has the key. No crash or runtime exception. One customer has this for “Mail” and one for “Outlook”. The only time I have seen something like this was with precomposed and decomposed UTF8 strings. But here???

I know about the dangers of variant. Thanks the gods you can’t see the abominations I have to do with VBA. The problem with the new framework for me is that this thing is convoluted as heck.

I’m getting the preferences with the MBS plugin. Ancient ancient code but still working well. The version of my app isn’t exactly new but so far the code only fails for High Sierra.

[code]dim s1 as string = “Hello”
dim s2 as string = ConvertEncoding(s1, encodings.UTF16)

dim v1 as Variant = s1
dim v2 as Variant = s2

dim h1 as integer = v1.Hash
dim h2 as integer = v2.Hash

dim d as new Dictionary

d.Value(s1) = nil

if d.HasKey(s2) then
end if[/code]

As you see hashes are different for different encoding, so maybe convert them to UTF8 always?

The code for getting the key is:

[code]Dim CFKey As CFObjectMBS
Dim Key As Variant

theDictionary = new Dictionary

For currentValue = 0 to dict.Count - 1
CFKey = dict.List.Key(currentValue)

//Determine the type of key
Select case CFKey.TypeDescription
Case “CFBoolean”
Key = CFBooleanMBS(CFKey).Value
Case “CFNumber”
Key = CFNumberMBS(CFKey).integerValue
Else //Use the string value
Key = CFStringMBS(CFKey).Str
End Select


This ends up with everything nicely in utf8.

Well, you can inspect key in dictionary and key you query for differences.
Maybe an invisible character is there?

the CFStringMBS str method should give UTF-8 string.

I wasn’t able to reproduce the issue. I didn’t see anything after having a look at the binary data. That’s why I asked how I can get the binary data from the user. Even the plist file from the user didn’t show anything.