It';这是我们在基本面向对象之前所拥有的
; @MP,
我的两美分
我想有#039;这与您的解决方案相反。大多数Acad函数(如有)不';t接受UDT#039;s、 例如,将WCS中的点转换为UCS坐标或vicaversa可能会出现问题
使用DoubleArray和变体赢得#039;我没有那个问题
哦,还有一个用于复制初始化索引数组的附加项……很难。如果可以,请使用';不要回避它
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, Source As Any, ByVal numBytes As Long)
Sub Test()
Dim P1(2) As Double
Dim P2(2) As Double
'P1(0) = 1: P1(1) = 2: P1(2) = 3
CopyArray P1, P2
MsgBox (P2(2))
End Sub
Sub CopyArray(Source() As Double, Target() As Double)
Dim NumOfBytes As Long
On Error GoTo NoElements
NumOfBytes = (UBound(Source) + 1) * LenB(Source(0))
ReDim Target(UBound(Source)) 'no need for a diffrent number of items to be a
'true copy and save checking if the target is large enough...
CopyMemory Target(0), Source(0), NumOfBytes
NoElements:
MsgBox "Empty Source array in Sub CopySourceArray() at " & Format$(Now(), "hh:nn ss"), vbCritical + vbOKOnly + vbMsgBoxSetForeground, "Void Array."
On Error GoTo 0
Exit Sub
End Sub
嗨,贝伦德
同意,AutoCAD不#039;t通常接受UDT
我不会';然而,不要仅仅因为这个原因就直接驳回他们。与许多封装的解决方案一样,在封面下使用的内容可能对调用方完全隐藏
开发者必须问他/她自己很多问题,比如…内在的还是基于Win32 API的技术?是否存在性能影响?是否存在潜在的迁移问题?给定的技术有多灵活?它是否与问题域和基本数据类型很好地一致?它是否避免变体(blech)?它很容易映射到其他语言吗?等等。我只是在准备思考的食物。这可能是,也可能不是米克提出解决方案的最有效方式。本人';我只是想通过确定一些选择来尽我的职责。我感谢你,因为你也在这样做
Mick的另一个例子是观察--Option Explicit
Type TPoint
Coord(0 To 2) As Double
End Type
Sub AnotherDemo ( )
Dim P1 As TPoint
P1.Coord(0) = 10
P1.Coord(1) = 20
Dim P2 As TPoint
P2 = P1
Debug.Print P2.Coord(0)
Debug.Print P2.Coord(1)
End Sub 我经常使用一个变体来传递double,但有时它会稍微慢一点,因为可以使用ismissing来检测它是否被传递
以下子项显示变体的速度是原来的两倍Sub PassTheDoubly()
Dim P1(2) As Double
Dim P2(2) As Double
Dim V As Variant
Dim i As Long, j As Integer
Dim T As Single
T = Timer
P1(0) = 23: P1(1) = 23: P1(2) = 23
For i = 0 To 1000000
For j = 0 To 2
P2(j) = P1(j)
Next j
Next i
Debug.Print "double time=" & Timer - T
T = Timer
For i = 0 To 1000000
V = P1
Next i
Debug.Print "Var time=" & Timer - T
End Sub 双倍时间=0.375
页:
1
[2]