MBS Xojo Developer Conference and Training
Join us from 3rd to 6th May 2017 in Berlin, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

ArrayIsAMBS(v as Variant, ClassName as string) as boolean
global method, System, MBS Util Plugin (Main),
Plugin version: 12.3, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Checks if variant contains an array of the given class type.
Example:
dim w() as MouseCursor
w.Append System.Cursors.ArrowEastWest
w.Append System.Cursors.ArrowNorthSouth

dim v as Variant = w

if ArrayIsAMBS(w, "MouseCursor") then
MsgBox "OK"
end if
Notes:
If the variant contains an array of some class, variant or object and has at least one value, the plugin checks this first value for being of type of the same class. Like an ISA check.
This helps to solve feedback case 12213.
Returns false if variant has no array, if variant is nil, if array is not an array of objects or if first object is nil.
BacktraceMBS(MaxFrames as Integer = 0, skip as Integer = 2) as string()
global method, System, MBS Util Plugin (Main),
Plugin version: 13.0, Mac: Yes, Win: No, Linux: Yes, Console & Web: No, Feedback.

Function: Queries the stack trace of the current function.
Example:
MsgBox Join(BacktraceMBS, EndOfLine)
Notes:
MaxFrames: How many steps to show at maximum. Default is 128 currently.
skip: How many entries to skip. Default is 2 to not show this function.
Requires Mac OS X 10.5 or Linux.
Skip is 2 to hide this plugin function in the list.
GetVariantArrayMBS(VariantContainingArray as Variant) as Variant()
global method, System, MBS Util Plugin (Main),
Plugin version: 14.0, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Queries a variant containing array for an array and returns it as an array of variant.
Example:
dim test() as Dictionary
test.Append new Dictionary

dim v() as Variant = GetVariantArrayMBS(test)
dim dic as Dictionary = v(0)
Break
Notes:
Works with all arrays of objects (any type).
Raises exception if the array can't be converted or the variant contains no array.
GetVariantArrayUboundMBS(v as Variant) as Integer
global method, System, MBS Util Plugin (Main),
Plugin version: 13.0, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Queries array ubound for an array inside a variant.
Notes:
If you have an array in the variant, you'd normally assign it to an array to query values from array.
This function queries ubound directly.
Returns -3 if variant is nil and -2 if variant contains not an object array.
Updated in 13.5 plugins to raise exception is array is nil.

Some examples using this method:

GetVariantArrayValueMBS(v as Variant, index as Integer) as Variant
global method, System, MBS Util Plugin (Main),
Plugin version: 13.0, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Queries an object from an array of objects inside a variant.
Example:
// some part of app builds an array
dim a() as pair
a.Append 1:"Hello"
a.Append 2:"World"

// passes it as Variant somewhere else

dim v as Variant = a

// and later you may want to get values back without knowing the array type

// this raises TypeMismatchException
'dim o() as Object = v

// so use plugin to get objects:
dim v1 as Variant = GetVariantArrayValueMBS(v, 0)
dim v2 as Variant = GetVariantArrayValueMBS(v, 1)

// now you can check type and cast to the object type
dim p1 as pair = v1
dim p2 as pair = v2

MsgBox p1.Right+" "+p2.Right
Notes:
This function is to allow getting objects from an array inside a variant without known the class used to declare array.
Returns nil on any error.
Updated in 13.5 plugins to raise exception is array is nil.
Also updated to work with object, variant, string, date, integer, double, single, boolean, Int64 arrays. Other array types will raise exception.

Some examples using this method:

MillisecondsMBS as Double
global method, System, MBS Util Plugin (Main),
Plugin version: 13.5, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Queries current milliseconds time.
Notes: Like Microseconds in Xojo (Real Studio), but queries system functions for milliseconds counter.
ObjectIsAMBS(o as object, ClassName as string) as boolean
global method, System, MBS Util Plugin (Main),
Plugin version: 12.3, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Checks if a given object is of a given class.
Example:
// you must know exact name of class

dim v as Variant = window1

if ObjectIsAMBS(v, "window1.window1") then
MsgBox "OK"
end if

v = System.Cursors.MagnifyLarger

if ObjectIsAMBS(v, "MouseCursor") then
MsgBox "OK"
end if
Notes:
Like ISA operator, but with class name as string.
Returns false if o is nil.
SetVariantArrayValueMBS(v as Variant, index as Integer, value as Variant)
global method, System, MBS Util Plugin (Main),
Plugin version: 16.2, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Sets an object from an array of objects inside a variant.
Example:
// some part of app builds an array
dim a() as pair

// passes it as Variant somewhere else

dim v as Variant = a

// and later you may want to put values in array without knowing object type for array

// this raises TypeMismatchException
'dim o() as Object = v

// so use plugin

SetVariantArrayValueMBS(v, 0, 1:"Hello")
SetVariantArrayValueMBS(v, 1, 2:"World")

MsgBox a(0).Right+" "+a(1).Right
Notes:
This function is to allow setting objects in an array inside a variant without known the class used to declare array.
Also updated to work with object, variant, string, date, integer, double, single, boolean, Int64 arrays. Other array types will raise exception.
Be sure to only put objects of right class in the array! Else you risk crashes.

If index is 1 bigger than ubound, we append an element.

The items on this page are in the following plugins: MBS Util Plugin.




Links
MBS REAL studio tutorial videos