Name
AddressOf Operator
Syntax
AddressOf procedurename-
procedurename(required) The name of a procedure that is referenced by the procedure delegate
Description
The AddressOf operator returns a procedure
delegate instance that references a specific procedure.
The AddressOf operator is used in the following
situations:
If a parameter to a procedure (a VB procedure or a Win32 API function) requires a function pointer (the address of a function), then we can pass the expression:
AddressOf functionname
where
functionnameis the name of the function. This function is called a callback function.AddressOfis also used to create delegate objects, as in:delg = New ADelegate(AddressOf obj.AMethod)
AddressOfis used to bind event handlers to events through theAddHandlerstatement:AddHandler Form1.Click, AddressOf Me.Form1Click
Examples of all three applications of AddressOf
can be found in Section 7.1 in Chapter 7.
VB.NET/VB 6 Differences
In VB 6, the AddressOf operator can only be used
in a call to a Windows API function. Moreover, the argument passed to
AddressOf must be the name of a procedure in a
standard code module. However, in VB.NET these restrictions no longer
apply.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access