Beispiel: Verwendung von Events

www.altova.com Dieses Kapitel drucken Vorherige Seite Eine Ebene nach oben Nächste Seite

Startseite >  Referenz für Programmierer > Applikations-API > Übersicht > Programmiersprachen > VBScript >

Beispiel: Verwendung von Events

Die Authentic-Ansicht unterstützt die Verbindung zu Events pro Objekt. Die Implementierung dieser Funktion basiert auf COM Connection Points und steht in Umgebungen zur Verfügung, die diesen Mechanismus unterstützen.

 

Das folgende Beispiel ist ein Beispiel für VBScript-Code, in dem gezeigt wird, wie man von einem VBScript-Projekt aus Events verwendet.

 

 

' --------------------------------------------------------------------------
' VBScript example that demonstrates how to use events.
' --------------------------------------------------------------------------
 
' Event handler for OnSelectionChanged event of AuthenticView
Function AuthenticViewEvent_OnSelectionChanged(objAuthenticRange)
  If objAuthenticRange.FirstTextPosition <> objAuthenticRange.LastTextPosition Then
      Call WScript.Echo("Selection: " & objAuthenticRange.Text & vbNewLine & vbNewLine & "Close this dialog.")
  Else
      Call WScript.Echo("Cursor position: " & objAuthenticRange.FirstTextPosition & vbNewLine & vbNewLine & "Close this dialog.")
  End If
End Function
 
' Start/access XMLSpy and connect to its automation interface.
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objSpy = GetObject("", "XMLSpy.Application")
' Make the UI of XMLSpy visible.
objSpy.Visible = True
 
' Find out user's personal folder and locate one of the installed XMLSpy examples.
personalFolder = WshShell.ExpandEnvironmentStrings("%UserProfile%")
majorVersionYear = objSpy.MajorVersion + 1998
xmlspyExamplesFolder = personalFolder & "\Documents\Altova\XMLSpy" & majorVersionYear  & "\Examples\"
docPath = xmlspyExamplesFolder & "ExpReport.xml"
 
' Create object to access windows file system and test if the our document exists.
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(docPath) Then
  ' open the document
  Call objSpy.Documents.OpenFile(docPath, False)
  set objDoc = objSpy.ActiveDocument
 
  ' switch active document to authentic view
   objDoc.SwitchViewMode 4 ' spyViewAuthentic
 
  ' Register for connection point events on the authentic view of the active document.
  ' Any function with a valid event name prefixed with "AuthenticViewEvent_" will
  ' be called when the corresponding event gets triggered on the specified object.
  set objView = objDoc.AuthenticView
  Call WScript.ConnectObject(objView, "AuthenticViewEvent_")
  Call WScript.Echo("Events are connected." & vbNewLine & vbNewLine & "Now set or move the cursor in XMLSpy." & vbNewLine & vbNewLine & "Close this dialog to shut down XMLSpy.")
 
  ' To disconnect from the events delete the reference to the object.
  set objView = Nothing
Else
  Call WScript.Echo("The file " & docPath & " does not exist.")
End If
 
' shut down XMLSpy when this script ends
objSpy.Visible = False


© 2019 Altova GmbH