扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:陶刚编译 来源: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 |
婵犵鈧啿鈧綊鎮樻径鎰畺闁靛ň鏅滄慨婊堟偨椤栨稓鎽冮柟鐑╂櫊瀹曟岸宕堕埡鍌滄殸闂佽鍨伴崢鏍姳閿涘嫭鍠嗘い銈呭姬婵☆偅婢樺Λ妤呮偂濞嗘挸瀚夐柍褜鍓熷顒侊紣娓氣偓閻涙捇鏌涘┑鍛樂缂佹鐭傞獮搴ㄥ焵椤掑嫬瀚夋い鏍ㄧ懁缁诲棝鏌熼褍鐏茬紒杈ㄧ箞閺屽洭鏁愰崟顓犳澖闁荤姳闄嶉崹钘壩i崟顖涘殜闁硅泛顫曢埀顒€锕︾槐鏃堝箣閻愬弬妤呮煛閸偄鐏﹂柛瀣墬缁傛帞鎹勯搹瑙勵啈闂佸搫瀚烽崹閬嶅磻瀹ュ鍎嶉柛鏇ㄥ墯娴犳ê霉閿濆棗鈻曢柍褜鍓氶弻銊ф閻愬鈻曢悗锝傛櫇椤忛亶鏌曢崱顓熷