Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Compare Database
- Option Explicit
- Private Const mModuleName As String = "IViewEvents"
- Public Sub OnBeforeDoSomething(ByVal Data As Object, ByRef Cancel As Boolean): End Sub
- Public Sub OnAfterDoSomething(ByVal Data As Object): End Sub
- Private Sub Class_Initialize()
- Err.Raise 5, mModuleName, AccessError(5) & " - Interface class must not be instantiated."
- End Sub
- Option Compare Database
- Option Explicit
- Private Const mModuleName As String = "IViewCommands"
- Public Sub DoSomething(ByVal arg1 As String, ByVal arg2 As Long): End Sub
- Private Sub Class_Initialize()
- Err.Raise 5, mModuleName, AccessError(5) & " - Interface class must not be instantiated."
- End Sub
- Option Compare Database
- Option Explicit
- Private Const mModuleName As String = "ViewAdapter"
- Public Event BeforeDoSomething(ByVal Data As Object, ByRef Cancel As Boolean)
- Public Event AfterDoSomething(ByVal Data As Object)
- Private mView As IViewCommands
- Implements IViewCommands
- Implements IViewEvents
- Public Function Initialize(View As IViewCommands) As ViewAdapter
- Set mView = mView
- Set Initialize = Me
- End Function
- Private Sub IViewCommands_DoSomething(ByVal arg1 As String, ByVal arg2 As Long)
- mView.DoSomething arg1, arg2
- End Sub
- Private Sub IViewEvents_OnBeforeDoSomething(ByVal Data As Object, ByRef Cancel As Boolean)
- RaiseEvent BeforeDoSomething(Data, Cancel)
- End Sub
- Private Sub IViewEvents_OnAfterDoSomething(ByVal Data As Object)
- RaiseEvent AfterDoSomething(Data)
- End Sub
- Option Compare Database
- Option Explicit
- Private Const mModuleName As String = "ViewAdapter"
- Private WithEvents mViewAdapter As ViewAdapter
- Private mData As Object
- Public Function Initialize(ViewAdapter As ViewAdapter) As Controller
- Set mViewAdapter = ViewAdapter
- Set Initialize = Me
- End Function
- Private Sub mViewAdapter_AfterDoSomething(ByVal Data As Object)
- ' Do stuff
- End Sub
- Private Sub mViewAdapter_BeforeDoSomething(ByVal Data As Object, ByRef Cancel As Boolean)
- Cancel = Not Data Is Nothing
- End Sub
- Option Compare Database
- Option Explicit
- Option Private Module
- Private Const mModuleName As String = "Constructors"
- Public Function NewViewAdapter(View As IViewCommands) As ViewAdapter
- With New ViewAdapter: Set NewViewAdapter = .Initialize(View): End With
- End Function
- Public Function NewController(ByVal ViewAdapter As ViewAdapter) As Controller
- With New Controller: Set NewController = .Initialize(ViewAdapter): End With
- End Function
- Option Compare Database
- Option Explicit
- Private Const mModuleName As String = "MyApplication"
- Private mController As Controller
- Public Function LaunchApp() As Long
- Dim frm As IViewCommands
- ' Open and assign frm here as instance of a Form implementing
- ' IViewCommands and raising events through the callback interface
- ' IViewEvents. It requires an initialization method (or property
- ' setter) that accepts an IViewEvents argument.
- Set mController = NewController(NewViewAdapter(frm))
- End Function
- Option Explicit
- Public Sub DoSomething()
- End Sub
- Option Explicit
- Implements ISomething
- Private Sub ISomething_DoSomething()
- 'the actual implementation
- End Sub
- Dim something As ISomething
- Set something = New Class1
- something.DoSomething
- '@Folder StackOverflowDemo
- Public Foo As String
- Public Event BeforeDoSomething()
- Public Event AfterDoSomething()
- Public Sub DoSomething()
- End Sub
- '@Folder StackOverflowDemo
- Implements Class1
- Private Sub Class1_DoSomething()
- 'method implementation
- End Sub
- Private Property Let Class1_Foo(ByVal RHS As String)
- 'field setter implementation
- End Property
- Private Property Get Class1_Foo() As String
- 'field getter implementation
- End Property
- '@Folder StackOverflowDemo
- Implements Class1
- Public Event BeforeDoSomething()
- Public Event AfterDoSomething()
- Private foo As String
- Private Sub Class1_DoSomething()
- RaiseEvent BeforeDoSomething
- 'do something
- RaiseEvent AfterDoSomething
- End Sub
- Private Property Let Class1_Foo(ByVal RHS As String)
- foo = RHS
- End Property
- Private Property Get Class1_Foo() As String
- Class1_Foo = foo
- End Property
- '@Folder StackOverflowDemo
- Option Explicit
- Private WithEvents SomeClass2 As Class2 ' Class2 is a "concrete" implementation
- Public Sub Test(ByVal implementation As Class1) 'Class1 is the interface
- Set SomeClass2 = implementation ' will not work if the "real type" isn't Class2
- foo.DoSomething ' runs whichever implementation of the Class1 interface was supplied
- End Sub
- Private Sub SomeClass2_AfterDoSomething()
- 'handle AfterDoSomething event of Class2 implementation
- End Sub
- Private Sub SomeClass2_BeforeDoSomething()
- 'handle BeforeDoSomething event of Class2 implementation
- End Sub
- Option Explicit
- Sub Main()
- Dim oClient As Client
- Set oClient = New Client
- oClient.Run
- End Sub
- Option Explicit
- Implements IEventListener
- Private Sub IEventListener_SomethingHappened(ByVal vSomeParam As Variant)
- Debug.Print "IEventListener_SomethingHappened " & vSomeParam
- End Sub
- Public Sub Run()
- Dim oEventEmitter As EventEmitter
- Set oEventEmitter = New EventEmitter
- oEventEmitter.ServerDoWork Me
- End Sub
- Option Explicit
- Public Sub SomethingHappened(ByVal vSomeParam As Variant)
- End Sub
- Option Explicit
- Public Sub ServerDoWork(ByVal itfCallback As IEventListener)
- Dim lLoop As Long
- For lLoop = 1 To 3
- Application.Wait Now() + CDate("00:00:01")
- itfCallback.SomethingHappened lLoop
- Next
- End Sub
- [
- uuid(0EA530DD-5B30-4278-BD28-47C4D11619BD),
- hidden,
- custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "Microsoft.Office.Interop.Access._FormEvents")
- ]
- dispinterface _FormEvents2 {
- properties:
- methods:
- [id(0x00000813), helpcontext(0x00003541)]
- void Load();
- [id(0x0000080a), helpcontext(0x00003542)]
- void Current();
- '/* omitted lots of other events for brevity */
- };
- [
- uuid(7398AAFD-6527-48C7-95B7-BEABACD1CA3F),
- helpcontext(0x00003576)
- ]
- coclass Form {
- [default] interface _Form3;
- [source] interface _FormEvents;
- [default, source] dispinterface _FormEvents2;
- };
- ' clsHUMAN
- Public Property Let FirstName(strFirstName As String)
- End Property
- ' clsEmployee
- Implements clsHUMAN
- Event evtNameChange()
- Private Property Let clsHUMAN_FirstName(RHS As String)
- UpdateHRDatabase
- RaiseEvent evtNameChange
- End Property
- Private WithEvents Employee As clsEmployee
- Private Sub Employee_evtNameChange()
- Me.cmdSave.Enabled = True
- End Sub
Add Comment
Please, Sign In to add comment