Name

AddressOf Operator

Synopsis

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. It 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 functionname is the name of the function. This function is called a callback function.

  • AddressOf is also used to create delegate objects, as in:

    delg = New ADelegate(AddressOf obj.AMethod)
  • AddressOf is used to bind event handlers to events through the AddHandler statement:

    AddHandler Form1.Click, AddressOf Me.Form1Click

Get VB.NET Language Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.