I have a base class and derived classes that relate to a set of documents I
process. e.g. DocBase, DocA, DocB, DocC. The processing of each document is
handled in teh derived classes, as you might imagine, but the base class has
properties and methods that are common to all documents.
The processing of each docuemnt can result in a range of document specific
errors, which I want to raise as events on the document object, but there
are some events that are common to all documents, so I would like to have
those raised in the base class. In fact, I want to raise all events through
a delegate in the base class so that the object owners don't have to do too
much work.
So, I have in mind something like this for the caller:
Main
Sub ProcessDocA
Dim doc As DocBase = New DocA(path)
doc.Process(Add ressOf DocA_ProcessErr or) <--- Problem here
End Sub
Sub ProcessDocB
Dim doc As DocBase = New DocB(path)
doc.Process(Add ressOf DocB_ProcessErr or) <--- Problem here
End Sub
Sub DocA_ProcessErr or(ByVal sender As Object, ByVal e As
DocAProcessErro rEventArgs)
' Prompt User
End Sub
Sub DocB_ProcessErr or(ByVal sender As Object, ByVal e As
DocBProcessErro rEventArgs)
' Prompt User
End Sub
My base class looks like this
Public MustInherit Class DocBase
Delegate Sub ProcessErrorEve ntHandler(ByVal sender As Object, ByVal
e As EventArgs)
Protected ProcessErrorCal lBack As ProcessErrorEve ntHandler
MustOverride Sub Process(ByVal callback As ProcessErrorEve ntHandler)
Protected Sub OnProcessError( ByVal e As EventArgs)
ProcessErrorCal lBack.Invoke(Me , e)
End Sub
End Class
My derived class looks like this
Public Class DocA
Inherits DocBase
Public Overrides Sub Process(ByVal processErrorCal lback As
ProcessErrorEve ntHandler)
MyBase.ProcessE rrorCallback = processErrorCal lback
DoProcessing()
End Sub
Private Sub Do Processing()
' Trap Error
MyBase.OnProces sError(New DocAProcessErro rEventArgs("Err or in
Doc A"))
End Sub
End Class
The problem is where I have arrowed above, becase the compiler doesn't like
an implicit narrowing conversion from DocA_ProcessErr or() to
ProcessErrorEve ntHandler.
I know this all looks very complicated, and perhaps unnecessarily so, but
can anyone suggest a better, more generic way to do this.
TIA
Charles
process. e.g. DocBase, DocA, DocB, DocC. The processing of each document is
handled in teh derived classes, as you might imagine, but the base class has
properties and methods that are common to all documents.
The processing of each docuemnt can result in a range of document specific
errors, which I want to raise as events on the document object, but there
are some events that are common to all documents, so I would like to have
those raised in the base class. In fact, I want to raise all events through
a delegate in the base class so that the object owners don't have to do too
much work.
So, I have in mind something like this for the caller:
Main
Sub ProcessDocA
Dim doc As DocBase = New DocA(path)
doc.Process(Add ressOf DocA_ProcessErr or) <--- Problem here
End Sub
Sub ProcessDocB
Dim doc As DocBase = New DocB(path)
doc.Process(Add ressOf DocB_ProcessErr or) <--- Problem here
End Sub
Sub DocA_ProcessErr or(ByVal sender As Object, ByVal e As
DocAProcessErro rEventArgs)
' Prompt User
End Sub
Sub DocB_ProcessErr or(ByVal sender As Object, ByVal e As
DocBProcessErro rEventArgs)
' Prompt User
End Sub
My base class looks like this
Public MustInherit Class DocBase
Delegate Sub ProcessErrorEve ntHandler(ByVal sender As Object, ByVal
e As EventArgs)
Protected ProcessErrorCal lBack As ProcessErrorEve ntHandler
MustOverride Sub Process(ByVal callback As ProcessErrorEve ntHandler)
Protected Sub OnProcessError( ByVal e As EventArgs)
ProcessErrorCal lBack.Invoke(Me , e)
End Sub
End Class
My derived class looks like this
Public Class DocA
Inherits DocBase
Public Overrides Sub Process(ByVal processErrorCal lback As
ProcessErrorEve ntHandler)
MyBase.ProcessE rrorCallback = processErrorCal lback
DoProcessing()
End Sub
Private Sub Do Processing()
' Trap Error
MyBase.OnProces sError(New DocAProcessErro rEventArgs("Err or in
Doc A"))
End Sub
End Class
The problem is where I have arrowed above, becase the compiler doesn't like
an implicit narrowing conversion from DocA_ProcessErr or() to
ProcessErrorEve ntHandler.
I know this all looks very complicated, and perhaps unnecessarily so, but
can anyone suggest a better, more generic way to do this.
TIA
Charles
Comment