扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:陶刚编译 来源:yesky 2007年11月9日
关键字:
Class AccountHandlers Shared Sub LogWithdraw(ByVal Amount As Decimal) '把撤消信息写入日志文件 End Sub Shared Sub GetApproval(ByVal Amount As Decimal) '阻塞直到管理者批准 End Sub End Class |
Dim handler1 As LargeWithdrawHandler handler1 = AddressOf AccountHandlers.LogWithdraw |
AddHandler <event>, <delegate object> |
'建立银行帐号对象 Dim account1 As New BankAccount() '建立并注册一个事件处理程序 Dim handler1 As LargeWithdrawHandler handler1 = AddressOf AccountHandlers.LogWithdraw AddHandler account1.LargeWithdraw, handler1 |
'建立银行帐号对象 Dim account1 As New BankAccount() '注册事件处理程序 AddHandler account1.LargeWithdraw, AddressOf AccountHandlers.LogWithdraw AddHandler account1.LargeWithdraw, AddressOf AccountHandlers.GetApproval |
Dim account1 As New BankAccount() '注册事件处理程序 AddHandler account1.LargeWithdraw, AddressOf AccountHandlers.LogWithdraw '删除事件处理程序注册 RemoveHandler account1.LargeWithdraw, AddressOf AccountHandlers.LogWithdraw |
Delegate Sub LargeWithdrawHandler(ByVal Amount As Decimal) Class BankAccount Public Event LargeWithdraw As LargeWithdrawHandler Sub Withdraw(ByVal Amount As Decimal) '如果需要的话就发送通知 If (Amount > 5000) Then RaiseEvent LargeWithdraw(Amount) End If '执行撤消 End Sub End Class Class AccountHandlers Shared Sub LogWithdraw(ByVal Amount As Decimal) '把撤消信息写入日志文件 End Sub Shared Sub GetApproval(ByVal Amount As Decimal) '阻塞直到管理者批准 End Sub End Class Module MyApp Sub Main() '建立银行帐号对象 Dim account1 As New BankAccount() '注册事件处理程序 AddHandler account1.LargeWithdraw, _ AddressOf AccountHandlers.LogWithdraw AddHandler account1.LargeWithdraw, _ AddressOf AccountHandlers.GetApproval '做一些触发回调的事情 account1.Withdraw(5001) End Sub End Module |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者