-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRefArray.cls
More file actions
1275 lines (1221 loc) · 39.8 KB
/
RefArray.cls
File metadata and controls
1275 lines (1221 loc) · 39.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "RefArray"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Private Const vbLongLong = 20
Private Type SAFEARRAYBOUND
cElements As Long
lLBound As Long
End Type
Private Type SAFEARRAY1D
cDims As Integer
fFeatures As Integer
cbElements As Long
cLocks As Long
pvData As Long
onebound(0 To 0) As SAFEARRAYBOUND
End Type
Private Declare Function HashData Lib "shlwapi" (ByVal straddr As Long, ByVal ByteSize As Long, ByVal res As Long, ByVal ressize As Long) As Long
Private mError As Long
Private p As Variant, emptytype As Integer
Private ihavearray As Boolean, isok As Boolean
Private Declare Function SafeArrayRedim Lib "oleaut32" (ByVal saPtr As Long, ByVal saBound As Long) As Long
Private OneDimension As Boolean
Public flat As Boolean
Public Function GetUDTValue(ByVal there, ByVal p As Long, Name$, Optional nDx)
On Error Resume Next
If IsMissing(nDx) Then
SwapVariant GetUDTValue, Value(there, p, Name$)
Else
SwapVariant GetUDTValue, Value(there, p, Name$, CLng(nDx))
End If
End Function
Friend Property Get emtype() As Integer
emtype = emptytype
End Property
Friend Property Let emtype(RHS As Integer)
emptytype = RHS
End Property
Friend Sub CreateRef(ByVal A As Long)
If flat Then
VarByRef A, p
Else
VarByRef A, p(0)
End If
End Sub
Private Sub VarByRef(ByVal A As Long, ByRef b As Variant)
Dim t(0 To 3) As Long
CopyMemory t(0), ByVal VarPtr(b), 16
t(0) = t(0) Or &H4000
t(2) = VarPtr(b) + 8
CopyMemory ByVal A, t(0), 16
End Sub
Function NewRef(Optional ByRef RHS) As refArray
Dim z As New refArray
If Not IsMissing(RHS) Then z.writevalue = RHS
z.flat = flat
Set NewRef = z
End Function
Friend Sub UnFlat()
Dim z, z1
If flat Then
z = p
ResetToType vbVariant, 0
CopyVariantArray p(0), z
CopyVariantArray z, z1
End If
End Sub
Property Get Copy() As refArray
Dim z As New refArray, pp, gr As Group
If isok Then
Dim i As Long, j As Long, M, rA As refArray
If flat Then
z.writevalue = p
z.flat = flat
If VarType(p) = vbArray + vbObject Then
For i = UBound(p) To 0 Step -1
If Not p(i) Is Nothing Then
If TypeOf p(i) Is refArray Then
Set M = p(i).Copy()
z(i) = M
ElseIf TypeOf p(i) Is Group Then
Dim MM As Object
Dim MMM As Object
Set MM = p(i)
CopyGroupObjRef MM, MMM
z(i) = CVar(MMM)
Else
Set M = p(i)
On Error GoTo 123
Set M = p(i).Copy()
123
z(i) = M
Err.Clear
Set M = Nothing
End If
End If
Next i
End If
Set Copy = z
Exit Property
End If
Dim ppp As Object
For i = UBound(p) To 0 Step -1
If IsObject(p(i)) Then
Set ppp = p(i)
If ppp Is Nothing Then
z(i) = CVar(Nothing)
ElseIf TypeOf p(i) Is refArray Then
Set rA = p(i)
If rA.MarkTwoDimension Then
Set rA = rA.Copy
rA.MarkTwoDimension = True
z(i) = CVar(rA)
Else
z(i) = CVar(rA.Copy)
End If
End If
Else
pp = p(i)
j = Elements(pp)
If VarType(pp) = vbVariant + vbArray Then
If j > 0 Then
For j = j - 1 To 0 Step -1
If IsObject(pp(j)) Then
Set M = pp(j)
On Error Resume Next
Set M = pp(j).Copy()
Err.Clear
If IsObjGroup(M) Then
z(i) = CVar(CopyGroupObj(M))
Else
z(i) = M
End If
Set M = Nothing
End If
Next j
End If
ElseIf VarType(pp) = vbArray + vbObject Then
If j > 0 Then
For j = j - 1 To 0 Step -1
Set M = pp(j)
If Not M Is Nothing Then
On Error Resume Next
Set M = M.Copy()
Err.Clear
Set ppp = M
If IsObjGroup(M) Then
Set z(i) = CopyGroupObj(M)
Else
Set z(j) = ppp
End If
End If
Set M = Nothing
Next j
End If
End If
z(i) = pp
End If
Next i
Else
z.writevalue = p
End If
z.MarkTwoDimension = Not OneDimension
z.emtype = emtype
Set Copy = z
End Property
Property Let writevalue(ByRef RHS)
If IsObject(RHS) Then
Set p = RHS
Else
ihavearray = (VarType(RHS) And vbArray) <> 0
' flat = VarType(RHS) = vbArray + vbVariant
p = RHS
If ihavearray Then
isok = Elements(p) > 0
End If
End If
End Property
Property Let Value(Optional where, Optional what, Optional WHAT1, Optional what2, that)
Dim mt As Integer, wt As Integer, ss$
If IsMissing(where) Then
If IsObject(that) Then
Set p = that
Else
If IsObject(p) Then Set p = Nothing: p = Empty
p = that
End If
ElseIf ihavearray Then
If isok Then
If UBound(p) < where Then
ReDim Preserve p(where)
End If
Else
ReDim p(where)
End If
entry1:
If IsMissing(what) Or flat Then
If flat And Not IsMissing(what) Then
If where = 0 Then
If VarType(what) = vbObject Then
Set p(what) = that
ElseIf VarType(p(what)) = vbLongLong Then
If Not VarType(that) = vbLongLong Then
that = cInt64(that)
End If
If Not VarType(that) = vbLongLong Then mError = 6: Exit Property
MemCopy ByVal ((ArrPtr() Xor &H80000000) + 8 * CLng(what)) Xor &H80000000, ((VarPtr(that) Xor &H80000000) + 8) Xor &H80000000, 8
Else
p(what) = that
End If
Else
If VarType(that) = vbObject Then
Set p(where) = that
ElseIf VarType(p(where)) = vbLongLong Then
If Not VarType(that) = vbLongLong Then
that = cInt64(that)
End If
If Not VarType(that) = vbLongLong Then mError = 6: Exit Property
MemCopy ((ArrPtr() Xor &H80000000) + 8 * CLng(where)) Xor &H80000000, ((VarPtr(that) Xor &H80000000) + 8) Xor &H80000000, 8
Else
p(where) = that
End If
End If
Else
On Error Resume Next
mt = vtType()
wt = VarType(that)
If wt = vbObject Then
If mt = 8201 Or mt = 8204 Then
If Me.emtype = 201 Then
If TypeOf that Is BigInteger Then
Set p(where) = that
Else
mError = 5050
End If
Else
Set p(where) = that
End If
Else
mError = 91
End If
ElseIf mt = 8201 Then ' vbObject + vbArray
If Me.emtype = 201 Then
Set p(where) = Module13.CreateBigInteger(Format(Int(that), "0"))
Else
mError = 91
End If
ElseIf mt = 8212 Then
If Not VarType(that) = vbLongLong Then
that = cInt64(that)
End If
If Not VarType(that) = vbLongLong Then mError = 6: Exit Property
MemCopy ((ArrPtr() Xor &H80000000) + 8 * CLng(where)) Xor &H80000000, ((VarPtr(that) Xor &H80000000) + 8) Xor &H80000000, 8
ElseIf mt = 8200 Then
If wt = vbString Then
p(where) = that
Else
mError = 5030
End If
ElseIf mt = 8199 Then
p(where) = CDate(that)
If Err Then mError = 5040: Err.Clear
ElseIf wt = vbString Then
If mt = vbVariant Or mt = vbString Or mt = 8204 Then
p(where) = that
Else
mError = 5020
End If
ElseIf wt = vbDate Then
p(where) = CDate(that)
ElseIf myVarType(that, vbObject) Then
Set p(where) = that
ElseIf (MemInt(VarPtr(that)) And vbArray) <> 0 Then
SwapVariant p(where), that
Else
p(where) = that
End If
If Err Then mError = Err.Number: Err.Clear
End If
ElseIf what >= 0 Then
If Elements(p(where)) < what + 1 Then
Dim i As Long
i = Elements(p(where))
Dim ThisPtr As Long, PadDim As SAFEARRAYBOUND
PadDim.cElements = what + 1
ThisPtr = MemLong(UnsignedAdd(VarPtr(p(where)), 8))
If SafeArrayRedim(ByVal ThisPtr, VarPtr(PadDim)) <> 0& Then Err.Raise 5
If Me.emtype = 200 Then
For i = i To what - 1
p(where)(i) = nMath2.cxZero
Next
ElseIf Me.emtype = 201 Then
For i = i To what - 1
Set p(where)(i) = ZeroBig
Next
End If
End If
On Error Resume Next
mt = vtType(where)
wt = VarType(that)
Select Case mt
Case vbDataObject ' 13 iUnKnown
If wt = vbDataObject Then
Set p(where)(what) = that
ElseIf myVarType(that, vbDataObject) Then
Set p(where)(what) = that
Else
mError = 91
End If
Case vbObject
If Me.emtype = 201 Then
If MemInt(VarPtr(that)) = 9 Then
If TypeOf that Is BigInteger Then
Set p(where)(what) = that
Else
mError = 5050
End If
Else
Set p(where)(what) = Module13.CreateBigInteger(Format(Int(that), "0"))
End If
ElseIf wt = vbObject Then
Set p(where)(what) = that
ElseIf myVarType(that, vbObject) Then
Set p(where)(what) = that
Else
mError = 91
End If
Case vbLongLong ' 20
If Not VarType(that) = vbLongLong Then
that = cInt64(that)
End If
If Not VarType(that) = vbLongLong Then mError = 6: Exit Property
MemCopy ByVal ((ArrPtr(where) Xor &H80000000) + 8 * CLng(what)) Xor &H80000000, ByVal ((VarPtr(that) Xor &H80000000) + 8) Xor &H80000000, 8
Case vbVariant
If Me.emtype = 200 Then
If MemInt(VarPtr(that)) <> 36 Then
p(where)(what) = nMath2.cxNew(CDbl(that), 0#)
ElseIf TypeOf that Is Complex Then
p(where)(what) = that
Else
WrongType
End If
ElseIf wt = vbObject Then
Set p(where)(what) = that
ElseIf myVarType(that, vbObject) Then
Set p(where)(what) = that
Else
p(where)(what) = that
End If
Case vbString
If wt = vbString Then
p(where)(what) = that
ElseIf wt = vbBoolean Then
p(where)(what) = Format$(that, DefBooleanString)
ElseIf wt = 20 Then
p(where)(what) = CStr(that)
Else
p(where)(what) = fixthis(that)
End If
Case vbDate
p(where)(what) = CDate(that)
If Err Then mError = 5040: Err.Clear
Case Else
If wt = vbString Then
mError = 5020
Else
p(where)(what) = that
End If
End Select
If Err Then mError = Err.Number: Err.Clear
End If
ElseIf Not IsMissing(where) Then
ihavearray = True
If where < 0 Then
p = what
isok = True
Else
p = Array()
ReDim p(where)
isok = True
GoTo entry1
End If
End If
End Property
Property Get Value(Optional where, Optional what, Optional WHAT1, Optional what2)
Attribute Value.VB_UserMemId = 0
Dim vv
If ihavearray Then
If isok Then
If IsMissing(where) Then
Exit Property
Else
If UBound(p) < where Then
ReDim Preserve p(where)
End If
End If
Else
ReDim Preserve p(where)
End If
If IsMissing(what) Or flat Then
If flat And Not IsMissing(what) Then
If where = 0 Then
If VarType(p(what)) = vbObject Then
Set Value = p(what)
ElseIf VarType(p(what)) = vbDataObject Then
Set Value = p(what)
ElseIf VarType(p(what)) = vbUserDefinedType Then
If Not IsMissing(WHAT1) Then
If VarType(WHAT1) = vbString Then
If IsMissing(what2) Then
SwapVariant Module10.GetUDTValue(p(what), CStr(WHAT1)), Value
Else
SwapVariant Module10.GetUDTValueArray(p(what), CStr(WHAT1), CLng(what2)), Value
End If
Else
Value = p(what)
End If
Else
Value = p(what)
End If
Else
Value = p(what)
End If
Else
Select Case VarType(p(where))
Case vbUserDefinedType
Case vbObject, vbDataObject
Set Value = p(where)
Case vbLongLong
MemCopy ((VarPtr(Value) Xor &H80000000) + 8) Xor &H80000000, ((ArrPtr() Xor &H80000000) + 8 * CLng(where)) Xor &H80000000, 8
MemInt(VarPtr(Value)) = vbLongLong
Case Else
Value = p(where)
End Select
End If
Else
Select Case VarType(p(where))
Case vbUserDefinedType
Case vbObject, vbDataObject ' vbDataObject is vt_IUnknown
Set Value = p(where)
Case vbLongLong
MemCopy ((VarPtr(Value) Xor &H80000000) + 8) Xor &H80000000, ((ArrPtr() Xor &H80000000) + 8 * CLng(where)) Xor &H80000000, 8
MemInt(VarPtr(Value)) = vbLongLong
Case Else
Value = p(where)
End Select
End If
Else
Dim pp As Long
pp = Elements(p(where))
If pp > 0 Then
If what >= 0 And what < pp Then
Select Case VarType(p(where)) - vbArray
Case vbObject, vbDataObject
Set Value = p(where)(what)
Case 20
MemCopy ((VarPtr(Value) Xor &H80000000) + 8) Xor &H80000000, ((ArrPtr(where) Xor &H80000000) + 8 * CLng(what)) Xor &H80000000, 8
MemInt(VarPtr(Value)) = 20
Case vbVariant
If Not IsMissing(WHAT1) Then
If VarType(WHAT1) = vbString Then
SwapVariant p(where), vv
If IsMissing(what2) Then
SwapVariant Module10.GetUDTValue(vv(what), CStr(WHAT1)), Value
Else
SwapVariant Module10.GetUDTValueArray(vv(what), CStr(WHAT1), CLng(what2)), Value
End If
SwapVariant p(where), vv
Else
Value = p(where)(what)
End If
Else
If VarType(p(where)(what)) = vbLongLong Then
MemCopy VarPtr(Value), ByVal ((ArrPtr(where) Xor &H80000000) + 16 * CLng(what)) Xor &H80000000, 16
ElseIf myVarType(p(where)(what), vbObject) Then
Set Value = p(where)(what)
Else
Value = p(where)(what)
End If
End If
Case Else
Value = p(where)(what)
End Select
End If
End If
End If
Else
If IsObject(p) Then
Set Value = p
Else
Value = p
End If
End If
End Property
Property Get AssignError()
AssignError = mError
mError = 0
End Property
Property Get Count(Optional M)
Count = 0&
If isok Then
If IsMissing(M) Then
Count = Elements(p)
ElseIf myVarType(p, vbObject) Then
If p Is Nothing Then
ElseIf TypeOf p Is refArray Then
If M >= 0 And M <= p.Count Then
On Error Resume Next
Count = p.Count(M)
Err.Clear
End If
End If
ElseIf M >= 0 And M <= UBound(p) Then
On Error Resume Next
Count = UBound(p(M)) + 1
Err.Clear
End If
End If
End Property
Sub UBoundTo(where)
If ihavearray Then
If isok Then
ReDim Preserve p(where)
End If
End If
End Sub
Property Get ArrPtr(Optional where) As Long
Dim pp As Long
If ihavearray Then
If isok Then
If IsMissing(where) Then
ArrPtr = MemLong(UnsignedAdd(VarPtr(p), 8))
ArrPtr = MemLong(UnsignedAdd(ArrPtr, 12))
Else
If Elements(p) <= where Then
ArrPtr = MemLong(UnsignedAdd(VarPtr(p(0)), 8))
ArrPtr = MemLong(UnsignedAdd(ArrPtr, 12))
ElseIf Elements(p(where)) > 0 Then
ArrPtr = MemLong(UnsignedAdd(VarPtr(p(where)), 8))
ArrPtr = MemLong(UnsignedAdd(ArrPtr, 12))
End If
End If
End If
End If
End Property
Property Get SafeArrPtr(Optional where) As Long
If ihavearray Then
If isok Then
If IsMissing(where) Then
SafeArrPtr = MemLong(UnsignedAdd(VarPtr(p), 8))
Else
Dim pp As Long
pp = Elements(p(where))
If pp > 0 Then
SafeArrPtr = MemLong(UnsignedAdd(VarPtr(p(where)), 8))
End If
End If
End If
End If
End Property
Function Elements(vArray As Variant) As Long
Dim lPtr As Long
Const VT_BYREF As Long = &H4000
If IsArray(vArray) Then
lPtr = MemLong(UnsignedAdd(VarPtr(vArray), 8))
If (MemLong(VarPtr(vArray)) And VT_BYREF) <> 0 Then
lPtr = MemLong(lPtr)
End If
If lPtr <> 0 Then
Elements = MemLong(UnsignedAdd(lPtr, 16))
End If
End If
End Function
Public Function Elements2(vArray As Variant) As Long
Dim lPtr As Long
Const VT_BYREF As Long = &H4000
If IsArray(vArray) Then
lPtr = MemLong(UnsignedAdd(VarPtr(vArray), 8))
If (MemLong(VarPtr(vArray)) And VT_BYREF) <> 0 Then
lPtr = MemLong(lPtr)
End If
If lPtr <> 0 Then
Dim i As Long, p As Long
p = 1
For i = 1 To MemInt(lPtr)
p = p * MemLong(UnsignedAdd(lPtr, 8 + i * 8))
Next i
Elements2 = p
End If
End If
End Function
Public Function UnsignedAdd(ByVal lUnsignedPtr As Long, ByVal lSignedOffset As Long) As Long
'--- note: safely add *signed* offset to *unsigned* ptr for *unsigned* retval w/o overflow in LARGEADDRESSAWARE processes
UnsignedAdd = ((lUnsignedPtr Xor &H80000000) + lSignedOffset) Xor &H80000000
End Function
Public Sub DefArrayAt(where, Arrtype, Optional Size As Long = 10, Optional Size1 As Long, Optional Size2 As Long)
Dim i As Long
If Size < 0 Then Size = 0
If ihavearray Then
If isok Then
If UBound(p) < where Then
ReDim Preserve p(where)
End If
Else
ReDim p(where)
End If
Else
ihavearray = True
p = Array()
If where = -1 Then
ReDim p(0)
Else
ReDim p(where)
End If
Me.emtype = Arrtype
isok = True
If Arrtype = 201 Then
End If
End If
Dim pp
If where = -1 Then
pp = LibMemory.EmptyArray(1, Arrtype)
ReDim pp(Size)
If Arrtype = 200 Then
For i = 0 To Size
pp(i) = nMath2.cxZero
Next i
'ElseIf Arrtype = 201 Then
' For I = 0 To Size
' pp(I) = ZeroBig
' Next I
End If
SwapVariant p, pp
Else
If Size1 <= 0 Then
pp = LibMemory.EmptyArray(1, Arrtype)
ReDim pp(Size)
If Arrtype = 200 Then
For i = 0 To Size
pp(i) = nMath2.cxZero
Next i
ElseIf Arrtype = 201 Then
For i = 0 To Size
Set pp(i) = ZeroBig
Next i
End If
ElseIf Size2 <= 0 Then
pp = LibMemory.EmptyArray(2, Arrtype)
ReDim pp(Size, Size1)
Else
pp = LibMemory.EmptyArray(3, Arrtype)
ReDim pp(Size, Size1, Size2)
End If
SwapVariant p(where), pp
End If
ihavearray = True
isok = True
If where > 0 Then OneDimension = False
End Sub
Property Get ItemType(item) As Long
On Error GoTo alfa
If ihavearray And isok Then
If Not IsMissing(item) Then
ItemType = MemInt(VarPtr(p(item)))
Else
ItemType = VarType(p)
End If
End If
Exit Property
alfa:
ItemType = -1
End Property
Public Function IsInnerRefArray(item, r As refArray) As Boolean
If ihavearray And isok Then
Dim pp As Object
If Me.MarkTwoDimension Then
If Elements(p) > item Then
If MemInt(VarPtr(p(item))) = 9 Then
Set pp = p(item)
If Not pp Is Nothing Then
If TypeOf pp Is refArray Then
Set r = pp
IsInnerRefArray = True
End If
End If
End If
End If
ElseIf Elements(p(0)) > item Then
If MemInt(VarPtr(p(0)(item))) = 9 Then
Set pp = p(0)(item)
If Not pp Is Nothing Then
If TypeOf pp Is refArray Then
Set r = pp
IsInnerRefArray = True
End If
End If
End If
End If
End If
End Function
Public Function tuple(ParamArray v())
Dim p() As Variant
p = v
If Elements(p) > 0 Then
tuple = p
Else
Dim z() As Variant
tuple = z()
End If
End Function
Property Get Hash(item As Long, Optional what As Long = -1, Optional ByVal Size As Long = 4) As Long
Dim mPtr As Long, ssize As Long
If Size < 1 Then Exit Property
If ihavearray And isok Then
Select Case VarType(Value(item))
Case 8200
If what < 0 Or what > UBound(p(item)) Then
Err.Raise 5
Else
mPtr = MemLong(UnsignedAdd(VarPtr(p(item)), 8))
mPtr = MemLong(UnsignedAdd(mPtr, 12))
mPtr = MemLong(mPtr + 4 * what)
If mPtr = 0 Then
Hash = 1
Else
ssize = MemLong(mPtr - 4)
HashData mPtr, ssize, VarPtr(Hash), Size
End If
End If
End Select
End If
End Property
Friend Function CompareStrEq(where As Long, what As Long, thisstr As String) As Boolean
Const CSTR_EQUAL As Long = 2&
Dim mPtr As Long, ssize As Long, lPtr As Long
mPtr = MemLong(((VarPtr(p(where)) Xor &H80000000) + 8) Xor &H80000000)
''SafeArrayAccessData mPtr, iPtr
mPtr = MemLong(((mPtr Xor &H80000000) + 12) Xor &H80000000)
mPtr = MemLong(mPtr + 4 * what)
If mPtr = 0 Then
GoTo ex1
Else
ssize = MemLong(mPtr - 4)
ssize = ssize \ 2
If ssize <> Len(thisstr) Then Exit Function 'GoTo ex1
If ssize = 0 Then CompareStrEq = True: Exit Function 'GoTo ex1
lPtr = StrPtr(thisstr)
While ssize > 0
If MemInt(lPtr) <> MemInt(mPtr) Then Exit Function
ssize = ssize - 1
lPtr = ((lPtr Xor &H80000000) + 2) Xor &H80000000
mPtr = ((mPtr Xor &H80000000) + 2) Xor &H80000000
Wend
CompareStrEq = True
End If
ex1:
''SafeArrayUnaccessData mPtr
End Function
Private Function VarTypeNameList(v, Optional addstr As String) As String
Dim n As Integer
n = MemInt(VarPtr(v))
Select Case n
Case 0
VarTypeNameList = "Empty"
Case 1
VarTypeNameList = "Null"
Case 2
VarTypeNameList = "Integer"
Case 3
VarTypeNameList = "Long"
Case 4
VarTypeNameList = "Single"
Case 5
VarTypeNameList = "Double"
Case 6
VarTypeNameList = "Currency"
Case 7
VarTypeNameList = "Date"
Case 8
VarTypeNameList = "String"
Case 9
VarTypeNameList = Typename(v)
Case 10
VarTypeNameList = "Error"
Case 11
VarTypeNameList = "Boolean"
Case 12, 1
VarTypeNameList = "Variant"
Case 13
VarTypeNameList = "Unknown"
Case 14
VarTypeNameList = "Decimal"
Case 17
VarTypeNameList = "Byte"
Case 20
VarTypeNameList = "Long Long"
Case 36
VarTypeNameList = Typename(v)
Case Is > 8192
VarTypeNameList = ArrayDesc(v, addstr)
Case Else
VarTypeNameList = "type" & VarType(v)
End Select
End Function
Public Function ArrayDesc(vArray As Variant, str As String) As String
Dim lPtr As Long
Const VT_BYREF As Long = &H4000
If IsArray(vArray) Then
lPtr = MemLong(UnsignedAdd(VarPtr(vArray), 8))
If (MemLong(VarPtr(vArray)) And VT_BYREF) <> 0 Then
lPtr = MemLong(lPtr)
End If
If lPtr <> 0 Then
Dim i As Long, p As String, aType As String
Select Case MemInt(VarPtr(vArray)) And &HFFF
Case 2
aType = "Integer"
Case 3
aType = "Long"
Case 4
aType = "Single"
Case 5
aType = "Double"
Case 6
aType = "Currency"
Case 7
aType = "Date"
Case 8
aType = "String"
Case 9 ' VT_DISPATCH = 9, VT_UNKNOWN = 13
aType = "Object"
Case 11
aType = "Boolean"
Case 12, 1
aType = "Variant"
Case 13
aType = "Unknown"
Case 14
aType = "Decimal"
Case 17 ' VT_UI1 = 17
aType = "Byte"
Case 20
aType = "Long Long"
Case 27 ' VT_SAFEARRAY = 27
aType = "Array"
Case 29 ' VT_USERDEFINED = 29
aType = "UDT"
Case 36
aType = Typename(vArray)
End Select
For i = 1 To MemInt(lPtr)
p = p & "[" & MemLong(UnsignedAdd(lPtr, 8 + i * 8)) & "]"
Next i
ArrayDesc = aType & str & p
Exit Function
End If
ArrayDesc = "EmptyArray"
Exit Function
End If
ArrayDesc = "type" & VarType(vArray)
End Function
Property Get vtTypeString(Optional where) As String
If ihavearray Then
If isok Then
If IsMissing(where) Or flat Then
If Not IsMissing(where) Then
vtTypeString = VarTypeNameList(p(where))
Else
If MarkTwoDimension Then
vtTypeString = VarTypeNameList(p(0), Mid$(VarTypeNameList(p), 8))
Else
vtTypeString = VarTypeNameList(p)
End If
End If
Else
vtTypeString = VarTypeNameList(p(where))
End If
End If
Else
vtTypeString = VarTypeName(emptytype)
End If
End Property
Private Function VarTypeName(nVarType As Integer) As String
Select Case nVarType
Case 0
VarTypeName = "CustomType"
Case 2
VarTypeName = "Integer"
Case 3, 10
VarTypeName = "Long"
Case 4
VarTypeName = "Single"
Case 5
VarTypeName = "Double"
Case 6
VarTypeName = "Currency"
Case 7
VarTypeName = "Date"
Case 8
VarTypeName = "String"
Case 9
VarTypeName = "Object"
Case 11
VarTypeName = "Boolean"
Case 12, 1, 36
VarTypeName = "Variant"
Case 13
VarTypeName = "Unknown"
Case 14
VarTypeName = "Decimal"
Case 17
VarTypeName = "Byte"
Case 20
VarTypeName = "Long Long"
Case 8192
VarTypeName = "Array"
Case Else
VarTypeName = "type" + Trim(str$(nVarType))
'Stop
End Select
End Function
Property Get vtType(Optional where, Optional Index) As Integer
If ihavearray Then
If isok Then
If IsMissing(where) Or flat Then
If Not IsMissing(where) Then
If VarType(p) = vbArray + vbVariant Then
vtType = MemInt(VarPtr(p(where)))
Else
vtType = VarType(p(where))
End If
Else
vtType = MemInt(VarPtr(p))
End If
Else
Dim pp As Long
If Elements(p) >= where Then
On Error Resume Next
pp = Elements(p(where))
If Err Then
vtType = -1
Exit Property
End If
If IsMissing(Index) Then
If pp > 0 Then
vtType = MemInt(VarPtr(p(where))) - vbArray
Else
vtType = MemInt(VarPtr(p(where))) ' not an array ??