Data Sharing Between Apps
Opening or Creating Contexts
Define a GlueContextManager instance and set its value using the GetGlueContext method passing the name of a context as an argument. Use the Open method of the GlueContextManager instance to open the selected context. If a context with the specified name doesn't exist, it will be automatically created.
Below is an example of a subroutine opening a context:
Dim WithEvents MyContext As GlueContextManager
Private Sub OpenContext()
On Error GoTo HandleErrors
Set MyContext = Glue.GetGlueContext("MyContext")
MyContext.Open
Exit Sub
HandleErrors:
' Handle exceptions.
End SubNote that when you declare a GlueContextManager instance with WithEvents, your app is automatically subscribed for the events exposed by GlueContextManager and you must provide implementations for handling these events.
Subscribing for Context Updates
To subscribe for context updates, use the HandleContextUpdate event exposed by the GlueContextManager instance. Its handler is executed when the context data has been updated.
Below is an example of a context update handler:
Private Sub MyContext_HandleContextUpdate(ByVal contextUpdate As IGlueContextUpdate)
Dim context As GlueContextManager
Set context = contextUpdate.GetContext
Dim ContextName as String
ContextName = context.GetContextInfo.Name
Dim Data
Set Data = context.GetReflectData("")
' or
Dim JsonData As String
JsonData = context.GetDataAsJson("")
' Examine the updated data.
...
On Error GoTo HandleErrors
Exit Sub
HandleErrors:
' Handle exceptions.
End SubUpdating Contexts
Use the SetValue method of the GlueContextManager instance to update the context data:
' Create a root composite value and add data in it.
Dim Data
Set Data = Glue.CreateGlueValues
Dim variantArray(0 To 1) As Variant
variantArray(0) = 1
variantArray(1) = "textValue"
Data("myTuple") = variantArray
' Updating a context.
MyContext.SetValue "data", DataAlternatively, use the UpdateContextDataJson method to update the context data using a JSON-formatted string:
MyContext.UpdateContextDataJson "data", "{""myTuple"":[1,""textValue""]}"To remove an existing composite or elementary value from the context, use the Remove method:
MyContext.Remove "data.myTuple"Listing All Available Contexts
To get a list of all available contexts, use the GetKnownContexts method:
Dim AllContexts() as GlueContext
AllContexts = Glue.GetKnownContexts()