摘要:Delegate

ModStandardCode
Public Module ModStandardCode 
Public Delegate Sub DSub0() Delegate Sub DSub0() 
Public Delegate Sub DSub1() Delegate Sub DSub1(ByVal pObject As Object) 
Public Delegate Sub DSub1Grid() Delegate Sub DSub1Grid(ByRef pGrid As C1.Win.C1FlexGrid.C1FlexGrid)
End ModuleSample Code 1

ClassFunctionPrivilege
"ClassFunctionPrivilege"#Region "ClassFunctionPrivilege" ' Used in : Cath Lab Reporting System
' Desc : give privilege based on user login,
' History :
' 2009-08-09 - Create this function
''' <summary>
''' Grant privilege based on Workgroup
''' </summary>
Public Class ClassFunctionPrivilege
Private mDSub1 As DSub1
''' <summary>
''' localizatize the enable function
''' </summary>
''' <param name="pSubEnableFunction">you should pass the local function in here. use addressof functionname</param> 
Public Sub SetSub() Sub SetSub(ByVal pSubEnableFunction As DSub1)
Try
Me.mDSub1 = pSubEnableFunction
Catch Err As Exception
Call ErrHandler(Err.Message, APP_NAME)
End Try
End Sub
''' <summary>
''' Enables the function.
''' </summary> 
Public Sub EnableFunction() Sub EnableFunction()
Try
Dim lsSQLString As String = BLANK
Dim ClsSQLLoadHelper As New ClassSQLLoadHelper
With ClsSQLLoadHelper
.TableName = "Workgroup_Function_Privilege WFP"
.SQLExtraSelect = ", Workgroup_User_Privilege WUP"
.SQLExtraCriteria = "WFP.Workgroup_Code = WUP.Workgroup_Code"
.SQLExtraCriteria += " And WUP.User_Code = " & VarSQLString(gsUserCode)
.AddRequiredField("Distinct WFP.Func_Code")
.SQLOrder = "WFP.Func_Code"
lsSQLString = .sGenerateSqlSelect
End With
Dim ClsGridHelper As New ClassGridHelper
With ClsGridHelper
.SetConnection(lsSQLString)
Try
While .bReadStart
Call mDSub1(.oLoadSQLField("Func_Code"))
End While
Finally
.bReadEnd()
End Try
End With
Catch Err As Exception
Call ErrHandler(Err.Message, APP_NAME)
End Try
End Sub
End Class
#End Region

How to use' Put me into Form Load
Dim ClsFunctionPrivilege As New ClassFunctionPrivilege
ClsFunctionPrivilege.SetSub(AddressOf EnableFunction)
ClsFunctionPrivilege.EnableFunction()
' Programmer should edit the following Code

Private Sub EnableFunction() Sub EnableFunction(ByVal psFunctionCode As Object)
Try
Select Case vntFixNull(psFunctionCode)
Case "EPR00"
Me.cmdePR.Enabled = True
Me.cmdePR.Visible = True
End Select
Catch Err As Exception
Call ErrHandler(Err.Message, APP_NAME)
End Try
End Sub
參考
huan-lin.blogspot.com/2009/01/delegate-revisited-csharp-1-to-2-to-3.html
------------------
熱愛生命 喜愛新奇 有趣的事物
過去 是無法改變
將來 卻能夠創造
希望使大家生活更便利
世界更美好
a guy who loves IT and life