重写Msgbox和Reporter对象
'重写Msgbox
Function NewMsgbox(text)
Print "Msgbox - " & text
End Function
Dim ptrMsgBox, MsgBox
'Get the reference to new function
Set ptrMsgBox = GetRef("NewMsgbox")
'Override the message box now
Set MsgBox = ptrMsgBox
'Now in every Action we just need to add two lines at the top to override the Msgbox method to our new one
Dim MsgBox
'Override the message box now
Set MsgBox = ptrMsgBox
'This way we can have the Function only in the library file and use its pointer everywhere to override the Function
'重写Reporter对象以及ReporterHTML方法
Dim oOrgReporter, oNewReporter
'The original reporter object
Set oOrgReporter = Reporter
Set oNewReporter = New NewReporter
Class NewReporter
'ReportEvent method
Function ReportEvent(Status, EventName, Description)
ReportEvent = oOrgReporter.ReportEvent(Status, EventName, Description)
End Function
'Getting the current filter value
Property Get Filter()
Filter = oOrgReporter.Filter
End Property
'Setting a new value for the filter
Property Let Filter(newValue)
oOrgReporter.Filter = newValue
End Property
'Run Status is read-only property, so we define the Get property only
Property Get RunStatus()
RunStatus = oOrgReporter.RunStatus
End Property
'ReportPath is read-only property, so we define the Get property only
Property Get ReportPath()
ReporterPath = oOrgReporter.ReportPath
End Property
Function ReportHTML(Status, EventName, HTMLText)
'Code to report the HTML text
End Function
End Class
'Now when we associate the above code in an associated library we have the new reporter object in the oNewReporter object with our added method.
'In Action:
Dim oOrgReporter, oNewReporter
'The original reporter object
Set oOrgReporter = Reporter
Set oNewReporter = New NewReporter
Execute "Dim Reporter"
Set Reporter = oNewReporter