You cannot pass a function, but you can pass an object that behaves like a function (sometimes called a "functor"). I use it all the time. If you use the "functor" class. Implements an interface, the call will be type safe. For example:
Abstract class (Interface) IAction.cls:
Option Explicit Public Sub Create(ByVal vInitArgs As Variant) End Sub Public Function exe() As Variant End Function
Functor displaying the URL in the default browser:
Option Explicit Implements IAction Dim m_sUrl As String Public Sub IAction_Create(ByVal vInitArgs As Variant) m_sUrl = vInitArgs End Sub Public Function IAction_exe() As Variant Call RunUrl(m_sUrl) 'this function is defined elsewhere Exit Function
Now you can create a bunch of these classes, save them in a collection, pass them to any function or method that expects IAction, etc.
cfischer
source share