Difference between revisions of "Interface"

From vb24
Jump to navigation Jump to search
(Created page with "== Interface == This is a sample implementation of an Interface event caught in a form. === IEvents === <syntaxhighlight lang="vb"> Public Sub Event1() End Sub Public Function ...")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Interface ==
 
== Interface ==
This is a sample implementation of an Interface event caught in a form.
 
  
 
=== IEvents ===
 
=== IEvents ===
 
<syntaxhighlight lang="vb">
 
<syntaxhighlight lang="vb">
 +
Option Explicit
 +
 
Public Sub Event1()
 
Public Sub Event1()
 
End Sub
 
End Sub
Line 13: Line 14:
 
=== IObject ===
 
=== IObject ===
 
<syntaxhighlight lang="vb">
 
<syntaxhighlight lang="vb">
 +
Option Explicit
 +
 
Public Property Get Value() As String
 
Public Property Get Value() As String
 
End Property
 
End Property
Line 38: Line 41:
 
Public Sub execute()
 
Public Sub execute()
 
     'Raise Event2
 
     'Raise Event2
     mIEvents.Event2(42)
+
     mIEvents.Event2()
 
End Sub
 
End Sub
  

Latest revision as of 02:30, 31 January 2012

Interface

IEvents

Option Explicit

Public Sub Event1()
End Sub

Public Function Event2(ByVal intParameter As Integer) As Integer
End Sub

IObject

Option Explicit

Public Property Get Value() As String
End Property

Public Sub execute()
End Sub

Public Sub setEventHandler(objEventHandler As IEvents)
End Sub

clsObject

Option Explicit

Implements IObject

Dim mIEvents As IEvents

Public Property Get Value() As String
    'Raise Event1
    mIEvents.Event1
End Property

Public Sub execute()
    'Raise Event2
    mIEvents.Event2()
End Sub

Public Sub setEventHandler(objIEvents As IEvents)
    Set mIEvents = objIEvents
End Sub

Form

Option Explicit

Implements IEvents

Dim objObject As clsObject

'IEvents implementation
Public Sub IEvents_Event1()
    'Event1 code
End Sub

Public Function IEvents_Event2(ByVal intParameter As Integer) As Integer
    'Event2 code
End Sub

'Form
Private Sub Form_Load()
    Set objObject = New clsObject
    objObject.setEventHandler Me
End Sub