we'll be covering some things every app must have: shared objects, and the
way to get some of the needed info into the shared objects: by getting it
out of the xml file.
' Draft of class #9 examples: (4/17/2011)
' example 1
' demonstrating one use for XML file: storage of string data
' The Strings method places text strings in the XML file into a
' dictionary object for easy retrieval. External strings allow for
' easy localization into other languages.
Dim myXMLFile
myXMLFile = ClientInformation.ScriptPath & "\Notepad_Duplicate_Windows.xml"
' the name I've given last week's final example
Dim myStrings
Set myStrings = Strings(myXMLFile) ' the strings() is a root level method
which returns a dictionary object
' now initialize the clientInformation object (a root level property of the
application object)
ClientInformation.ScriptName = myStrings("SCRIPT_NAME")
ClientInformation.ScriptVersion = myStrings("SCRIPT_VERSION")
ClientInformation.ScriptDescription = myStrings("SCRIPT_DESCRIPTION")
' end of example 1
' example 2
' shows the easy way to get a shared object (in this case, the one used for
error reporting)
dim oErrorReporting
Set oErrorReporting =
SharedObjects.Get("com.GWMicro.GWToolkit.ErrorReporting", 5000)
' the first parameter above is a combination of the "name space" used by GW,
and the specific object name;
' the second parameter is the number of milliseconds to wait for the object
before returning
If not oErrorReporting Is Nothing Then
' below lines are taken from the instructions for how to use the error
reporting object
sCode = oErrorReporting("1.0", "[email protected]", True)
ExecuteGlobal sCode
end if
' end of example 2
' example 3
' here's the recommended way to get a shared object, by making use of the
event which tells you when each shared object is available.
' now connect to the onStateChange event of the sharedObjects object (which
is a root level property).
Dim errorReportingEnabled
errorReportingEnabled = False
ConnectEvent SharedObjects, "OnStateChange", "HandleStateChange"
' end of main body
Function HandleStateChange(objName, objState)
' event handler for the onStateChange event of the sharedObjects object.
' the first parameter is the name of the object, and the second is true if
it's available, and false if not.
' this event gets triggered for each shared object when your app starts, as
well as when new ones come online or go offline.
HandleStateChange = False
Select Case objName
' you only list CASE options for the objects you are interested in using
' even though you will receive a notification for all possible objects.
Case "com.GWMicro.GWToolkit.ErrorReporting"
If objState Then
' object is available
' (here you put the commands specific to use of this object when it is
loaded)
If Not errorReportingEnabled Then
ExecuteGlobal SharedObjects(objName,
0)(ClientInformation.ScriptVersion, "[email protected]", True)
errorReportingEnabled = True
End If
else
' object has become unavailable (maybe it's script has crashed)
' so maybe you do something in your script such as undefine a hotkey which
used this object, gray out some menu choices, whatever.
end if
end select
HandleStateChange = True ' indicates you have handled this notification
end function
' end of example 3
' example 4
' showing the setup of the standard help object from the GW toolkit
Dim myINIFile : myINIFile = ClientInformation.ScriptPath &
"\Notepad_Duplicate_Windows.ini"
Dim myXMLFile
myXMLFile = ClientInformation.ScriptPath & "\Notepad_Duplicate_Windows.xml"
' The myStrings variable places text strings in the XML file into a
' dictionary object for easy retrieval. External strings allow for
' easy localization into other languages.
Dim myStrings
Set myStrings = Strings(myXMLFile) ' strings is a root level method of the
application object
Set SO_StandardHelpDialog = Nothing
ClientInformation.ScriptHelp = myStrings("GWToolkit_Required")
ConnectEvent SharedObjects, "OnStateChange", "HandleStateChange"
' end of main body
Function HandleStateChange(objName, objState)
' event handler for the onStateChange event of the sharedObjects object.
Select Case objName
If objName = "com.GWMicro.GWToolkit.StandardHelpDialog" Then
If objState Then
' it's available
Set SO_StandardHelpDialog = SharedObjects(objName, 0).NewDialog
SO_StandardHelpDialog.INIFileName = myINIFile
SO_StandardHelpDialog.HelpTitle = ClientInformation.ScriptName & " " &
ClientInformation.ScriptVersion
SO_StandardHelpDialog.HelpText = myStrings("SCRIPT_HELP")
SO_StandardHelpDialog.ScriptName = ClientInformation.ScriptName
SO_StandardHelpDialog.ScriptVersion = ClientInformation.ScriptVersion
SO_StandardHelpDialog.FocusCloseButton = True
SO_StandardHelpDialog.UpdateUrl = myScriptUpdateURL
SO_StandardHelpDialog.UseAboutBox = True
SO_StandardHelpDialog.AboutAuthor = "Chip Orange"
Dim fsObj : Set fsObj = CreateObject("Scripting.FileSystemObject")
SO_StandardHelpDialog.AboutReleaseDate =
fsObj.GetFile(ClientInformation.ScriptPath & "\" &
ClientInformation.ScriptFileName).DateLastModified
Set fsObj = Nothing
SO_StandardHelpDialog.AboutCopyright = ""
SO_StandardHelpDialog.AboutWebsite = ""
' Change ClientInformation.ScriptHelp to our real routine
ClientInformation.ScriptHelp = "ScriptHelp"
Else
' Change ClientInformation.ScriptHelp to our default
message
Set SO_StandardHelpDialog = Nothing
ClientInformation.ScriptHelp = myStrings("GWToolkit_Required")
End If
end if
end function
Sub ScriptHelp()
' after the help object has been initialized by the onStateChange event
handler above, this routine will be executed when the user presses the help
button in the app manager or chooses the help menu choice in the app's menu.
' before the help object is initialized, if the user asks for help, they
would get only the text stored in the .scriptHelp property of the
clientInformation object.
SO_StandardHelpDialog.Show
End Sub
' end of example 4