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:

[code]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
		Return defaultValue
	end if
End Function

End Module[/code]

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:

[code]EventHandler Sub Open()

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", "?")


End EventHandler[/code]

Please do not hesitate to contact us with questions.

1 Like

Brilliant. Thank you, simplifies life a lot.

1 Like