在指派運算 符右側具有屬性名稱的呼叫中,Visual Basic 會呼叫 Property Get 以從類別/物件傳回資訊。
在指派運算 符左側具有屬性名稱的呼叫中,Visual Basic 會呼叫 Property Let 或 Property Set 來更新類別物件內的資訊。
如果屬性過程的宣告有多個參數,呼叫 Property Let 或 Property Set,則會將指派運算符右側的 自變數傳遞至 Property Let 或 Property Set 程式的最後一個參數。
例如,下圖使用 Property Let 來顯示屬性過程調用 (頂端) 的自變數如何與下) 上宣告 (中的參數相關:
下列程式代碼範例示範屬性過程自變數和參數之間的關聯性。
'DemoType class declaration
Private pW
Private pX
Private pY
Private pZ
Property Get DemoProperty(w, x, y)
'Calling format is: `z = DemoProperty(w, x, y)`
' or `Set z = DemoProperty(w, x, y)`
w = pW
x = pX
y = pY
If IsObject(pZ) Then
Set DemoProperty = pZ
Else
DemoProperty = pZ
End If
End Property
Property Let DemoProperty(w, x, y, z)
'Calling format is `DemoProperty(w, x, y) = z`
pW = w
pX = x
pY = y
pZ = z
End Property
Property Set DemoProperty(w, x, y, z As Object)
'Calling format is `Set DemoProperty(w, x, y) = z`
pW = w
pX = x
pY = y
Set pZ = z
End Property
Sub DemoSub()
Dim myDemo As Object
Dim a, b, c, d
Dim w, x, y, z
Set myDemo = New DemoType
a = "Hello"
b = ", "
c = "world"
d = "!"
Debug.Print Join(Array(a, b, c, d), "") ' Hello, world!a
'Call Property Let DemoProperty(a, b, c, d)
Let myDemo.DemoProperty(a, b, c) = d
'Call Property Get
d = myDemo.DemoProperty(a, b, c)
Debug.Print Join(Array(a, b, c, d), "") ' Hello, world!
End Sub
Do you want to create custom procedures in AL? This module focuses on explaining how you can create new procedures. Additionally, it describes the difference between local and global procedures, the difference between local and global variables, and how you can pass variables to a procedure.