![]() ![]() We put in some safe guards, so it will raise an exception if something isn't as expected. ![]() Our plugin function does exactly that and helps to process easily arrays of Dictionary stored in variant. Our code to convert JSON to Xojo objects uses dictionary arrays, but how to cast them correctly? Well, in Xojo you have no way to check whether an array is of type object/variant and then check whether all items inside are Dictionary (or nil). The GetVariantAsDictionaryArrayMBS function is relatively new in one of the last releases. Need to set a value in an array? You can use SetVariantArrayValueMBS function to set a value in any type of array universally. The functions GetVariantArrayValueMBS and GetVariantArrayUboundMBS allow us to look into all arrays in our Web Starter Kit, where we have a memory browser feature. As our plugin knows the upper bound, we can do bounds checking and raise an OutOfBoundsException if needed and include a message text of course. You simply pass index, we lookup type of array and carefully check which variant value to return. No need to query type and assign to local variable, risking a TypeMismatchException. The GetVariantArrayValueMBS function allows you to query an array values independent of the type of array as variant. ![]() Our GetVariantArrayUboundMBS function makes this easier as it works for all array types. You would have to query the type of array, then assign to a matching local variable, handle over 20 types for that then know the upper bound. When you have a variant of some type of array, you have no way in Xojo to know the upper bound easily (see Feedback case 31799). If so, we return it as an array of variant and you can use it. Our GetVariantArrayMBS function checks whether the variant contains an array of type object. This raises a TypeMismatchException without explanation message. But you can't just assign an array inside a variant to an array of variant in Xojo. We often encounter variants containing arrays and like to assign them to a local variable in Xojo. Beside the internal routines to convert from/to various classes like SAValue, NSObject, CFObject, PROPVARIANT and VARAINT and Xojo variants, we got a lot of useful helps for your daily coding. Variant Helper functions in MBS Xojo Plugins Over time we collected a few functions in our plugins to help with variants. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |