1

我有一个实现另一个对象的类。我为实现对象的每个属性设置了一个属性函数,但不断收到“无效使用属性”错误。这是我的代码:

测试子:

Sub tst()

Dim a As Derived

Set a = New Derived

a.Base_name = "ALGO" 'Error happens when this executes
End Sub

派生类模块:

Option Explicit
Implements Base
Private sec As Base
Private Sub Class_Initialize()
    Set sec = New Base
End Sub
Public Property Get Base_name() As String
    Call sec.name
End Property
Public Property Let Base_name(value As String)
    Call sec.name(value) 'Error happens here
End Property

基类模块:

Private pname As String

Public Property Get name() As String
    name = pname
End Property
Public Property Let name(value As String)
    pname = value
End Property
4

1 回答 1

3

这是你想要的吗?

模块1

Sub tst()

Dim a As Derived

Set a = New Derived

Debug.Print a.Base_name
a.Base_name = "ALGO"
Debug.Print a.Base_name
End Sub

基类模块

Private pname As String

Public Property Get name() As String
    name = pname
End Property
Public Property Let name(value As String)
    pname = value
End Property

派生类模块

Option Explicit
Implements Base
Private sec As Base
Private Sub Class_Initialize()
    Set sec = New Base
End Sub
Public Property Get Base_name() As String
    Base_name = sec.name
End Property
Public Property Let Base_name(value As String)
    sec.name = value
End Property
于 2012-09-14T20:49:36.337 回答