请发表友善的回复…
发表回复
kmzs 2006-03-14
- 打赏
- 举报
就算子类化了也不稳定,REALbasic支持继承和运算符过载。
jobs002 2006-03-14
- 打赏
- 举报
由于在vb中不能实现类的继承机制,所以需要在类的定义的时候加入一个继承的类的成员已作为继承,例如
option explicit
dim ctlcontrols as classBase
public sub Class_Initialize
set ctlControls=new classBase
end sub
public sub Class_Termitede
set ctlControls=nothing
end sub
option explicit
dim ctlcontrols as classBase
public sub Class_Initialize
set ctlControls=new classBase
end sub
public sub Class_Termitede
set ctlControls=nothing
end sub
sunwood 2006-03-14
- 打赏
- 举报
没听说vb的类能够继承
vansoft 2006-03-14
- 打赏
- 举报
類cBase
Option Explicit
Private mvarBaseProperty As String
Public Sub BaseFunction()
MsgBox "Hello world!"
End Sub
Public Property Let BaseProperty(ByVal VData As String)
mvarBaseProperty = VData
End Property
Public Property Get BaseProperty() As String
BaseProperty = mvarBaseProperty
End Property
類cInherit
Option Explicit
Implements cBase
Dim m_BaseProperty As String
Private Property Get CBase_BaseProperty() As String
BaseProperty = m_BaseProperty
End Property
Private Property Let CBase_BaseProperty(ByVal VData As String)
m_BaseProperty = VData
End Property
Private Sub CBase_BaseFunction()
MsgBox "Inherit"
End Sub
Public Sub InheritMsg()
MsgBox "my owner msg"
End Sub
窗體Form1,有三個按鈕
Option Explicit
Private Sub Command1_Click()
Dim objTest As cBase
Set objTest = New cBase
objTest.BaseFunction '調用基類的方法
Set objTest = Nothing
End Sub
Private Sub Command2_Click()
Dim objTest As cBase
Set objTest = New cInherit
objTest.BaseFunction '調用繼承的方法
Set objTest = Nothing
End Sub
Private Sub Command3_Click()
Dim objTest As cInherit
Set objTest = New cInherit
objTest.InheritMsg '調用繼承類自己的方法
Set objTest = Nothing
End Sub
Option Explicit
Private mvarBaseProperty As String
Public Sub BaseFunction()
MsgBox "Hello world!"
End Sub
Public Property Let BaseProperty(ByVal VData As String)
mvarBaseProperty = VData
End Property
Public Property Get BaseProperty() As String
BaseProperty = mvarBaseProperty
End Property
類cInherit
Option Explicit
Implements cBase
Dim m_BaseProperty As String
Private Property Get CBase_BaseProperty() As String
BaseProperty = m_BaseProperty
End Property
Private Property Let CBase_BaseProperty(ByVal VData As String)
m_BaseProperty = VData
End Property
Private Sub CBase_BaseFunction()
MsgBox "Inherit"
End Sub
Public Sub InheritMsg()
MsgBox "my owner msg"
End Sub
窗體Form1,有三個按鈕
Option Explicit
Private Sub Command1_Click()
Dim objTest As cBase
Set objTest = New cBase
objTest.BaseFunction '調用基類的方法
Set objTest = Nothing
End Sub
Private Sub Command2_Click()
Dim objTest As cBase
Set objTest = New cInherit
objTest.BaseFunction '調用繼承的方法
Set objTest = Nothing
End Sub
Private Sub Command3_Click()
Dim objTest As cInherit
Set objTest = New cInherit
objTest.InheritMsg '調用繼承類自己的方法
Set objTest = Nothing
End Sub