« Check out options for… | Home | Checkout Machine Lear… »

Extends MBS Plugin classes in Xojo

If you miss something in our classes, feel free to extend the classes with your own utility functions. To do so in Xojo, please use a module with methods using extends keyword to add your own convenience functions. For example a client asked about a Lookup function for JSONMBS class:

Module JSONUtilModule
Function LookupValue(extends j as JSONMBS, name as string, defaultValue as string = "") As string Dim c As JSONMBS = j.Child(name) If c <> Nil Then Return c.ValueString Else Return defaultValue end if End Function
End Module

As you see this is a public method in a module and it extends the JSONMBS class with a new LookupValue method. The method can be called on all JSONMBS objects to check if a child there exists and return the string value. If the value is missing, it returns a default value.

Here is some test code checking whether the LookupValue function works:

EventHandler Sub Open() Dim jMBS As JSONMBS = JSONMBS.NewObjectNode jMBS.AddItemToObject("key1", JSONMBS.NewStringNode("aaa")) jMBS.AddItemToObject("key2", JSONMBS.NewStringNode("bbb")) jMBS.AddItemToObject("key3", JSONMBS.NewStringNode("ccc")) Dim n1 As String = jMBS.LookupValue("key1") Dim n5 As String = jMBS.LookupValue("key5", "?") Break End EventHandler

Please do not hesitate to contact us with questions.

22 05 20 - 09:57