猛跑小猪
这就是我的用途。这类似于GSerg的答案,但使用了更好的文档CopyMemory API函数,并且完全是自包含的(您只需将数组而不是ArrPtr(数组)传递给此函数)。它确实使用了VarPtr函数,微软警告说,但这是一个仅限XP的应用程序,它可以工作,所以我不担心。是的,我知道这个函数会接受你抛出的任何东西,但是我会把错误检查留给读者练习。Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _ (pDst As Any, pSrc As Any, ByVal ByteLen As Long)Public Function ArrayIsInitialized(arr) As Boolean
Dim memVal As Long
CopyMemory memVal, ByVal VarPtr(arr) + 8, ByVal 4 'get pointer to array
CopyMemory memVal, ByVal memVal, ByVal 4 'see if it points to an address...
ArrayIsInitialized = (memVal <> 0) '...if it does, array is intializedEnd Function