Здравствуйте уважаемые.
Не подскажите ли как, в VB6, можно передать событие из класса в форму?
Есть код:
Форма:
Private WithEvents UsersGroups As cGroup
Private Sub Form_Load()
Set UsersGroups = New cGroup
UsersGroups.Add "Вася"
UsersGroups.Add "Петя"
UsersGroups.Add "Дима"
UsersGroups.Item("Петя").Status = stOnline
End Sub
Private Sub UsersGroups_Changed(ByVal uName As String)
MsgBox uName
End Sub
и два класса
первый, cGroup:
Option Explicit
Private WithEvents CollMember As cUser
Public Event Changed(ByVal uName As String)
Private UsersArray As Collection
Public Function Add(ByVal Name As String, Optional Status As eStatus = stOffline) As cUser
Dim objNewMember As cUser
Set objNewMember = New cUser
With objNewMember
.UserName = Name
.Status = Status
End With
UsersArray.Add objNewMember, Name
Set Add = objNewMember
Set objNewMember = Nothing
End Function
Public Function Item(IndexKey As Variant)
Set Item = UsersArray.Item(IndexKey)
End Function
Public Sub Remove(IndexKey As Variant)
UsersArray.Remove IndexKey
End Sub
Private Sub Class_Initialize()
Set UsersArray = New Collection
End Sub
Private Sub Class_Terminate()
Set UsersArray = Nothing
End Sub
Private Sub CollMember_Changed(ByVal uName As String)
RaiseEvent Changed(uName)
End Sub
и второй, cUser:
Option Explicit
Public Enum eStatus
stOffline
stOnline
End Enum
Public Event Changed(ByVal uName As String)
Private uName As String
Private uStatus As eStatus
Public Property Get UserName() As String
UserName = uName
End Property
Public Property Let UserName(ByVal sValue As String)
uName = sValue
End Property
Public Property Get Status() As eStatus
Status = uStatus
End Property
Public Property Let Status(ByVal eValue As eStatus)
uStatus = eValue
RaiseEvent Changed(uName)
End Property
При изменении, в форме, статуса "Пети" на stOnline, Event из cUser передается только в cGroups.
А как можно передать Event из класса cUser в форму?
Заранее спасибо.
Ответить
|