VB实现委托
源码:


'作者:ioriliao '个人博客:http://'文件名:Delegate.cls '定义一个接口 Public Sub printf(ByVal str As String) End Sub

'作者:ioriliao '个人博客:http://'文件名:func1.cls '继承接口 Implements Delegate '实现接口 Private Sub Delegate_printf(ByVal str As String) MsgBox str End Sub

'作者:ioriliao '个人博客:http://'文件名:func2.cls '继承接口 Implements Delegate '实现接口 Private Sub Delegate_printf(ByVal str As String) MsgBox str MsgBox str & " " & Now End Sub

Private Sub printf(ByVal del As Delegate, ByVal str As String) Call del.printf(str) End Sub Private Sub Command1_Click() Call printf(New func1, "hello") Call printf(New func2, "hi") End Sub

[[it] 本帖最后由 ioriliao 于 2008-10-21 23:30 编辑 [/it]]