Delegates are function pointers that store function address.
There are 3 steps to understand Delegates:
Nothing fancy; just memorize the above steps to absorb the whole idea.
'How to define?
Public Delegate Sub testfile(Byval filename As String)
'instantiating the delegate
Dim mytestfile As testfile
Private Sub DoWork()
'now assign the address of function to the delegate
'or
MsgBox(filename)
End Sub
Now FileTester is really the function will be called which just shows the filename
Happy coding!
There are 3 steps to understand Delegates:
- Defining Delegate
- Instantiating Delegate
- Assigning Address of function to Delegate
Nothing fancy; just memorize the above steps to absorb the whole idea.
'How to define?
Public Delegate Sub testfile(Byval filename As String)
'instantiating the delegate
Dim mytestfile As testfile
Private Sub DoWork()
'now assign the address of function to the delegate
mytestfile = AddressOf FileTester
'it can be called as
'it can be called as
mytestfile("test.txt")
mytestfile.Invoke("test.txt")
End Sub
Public Sub FileTester(ByRef filename As String)MsgBox(filename)
End Sub
Now FileTester is really the function will be called which just shows the filename
Happy coding!
No comments:
Post a Comment