Results 1 to 10 of 10

Thread: Another huge game changer feature: Delegate function pointer types (Call by pointer)

Threaded View

  1. #3

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,654

    Re: Another huge game changer feature: Delegate function pointer types (Call by point

    tB has some support for generics in sub/function and classes, but doesn't support them with delegates yet. Or whatever the heck that 2nd argument at the Filter callsite.

    I started seeing how close I could get and I'll come back to it later, for now here's some generics examples working right now.

    Code:
    Module testmod
            Private Sub testc()
    
                Dim names As List(Of String) = New List(Of String)(Array("John", "Smith", "Kane", "Tessa", "Yoland", "Royce", "Samuel"))
                Dim s As String = names(0)
                Debug.Print s
            End Sub
    End Module
    [COMCreatable(False)]
    Class List(Of T)
        Private src() As T
        Private c As Long
        Sub New(p() As T)
            For i As Long = 0 To UBound(p)
                ReDim Preserve src(c)
                src(c) = p(i)
                c += 1
            Next
        End Sub
        [DefaultMember]
        Function GetAt(ByVal idx As Long) As T
            Return src(idx)
        End Function
        Public Property Get Count() As Long
            Return c
        End Property
    End Class
    Code:
        Public Function GetMem(Of T)(ByVal ptr As LongPtr) As T
            vbaCopyBytes(LenB(Of T), VarPtr(GetMem), ptr)
        End Function
        Public Function DCast(Of T, T2)(ByVal v As T2) As T
            If LenB(Of T2) >= LenB(Of T) Then
                vbaCopyBytes(LenB(Of T), VarPtr(DCast), VarPtr(v))
            Else
                vbaCopyBytes(LenB(Of T2), VarPtr(DCast), VarPtr(v))
            End If
        End Function
    Last edited by fafalone; May 23rd, 2025 at 12:33 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width