[dba-VB] inheriting events

jwcolby jwcolby at colbyconsulting.com
Mon Dec 31 16:00:19 CST 2007


I designed a base class which has events:


Public Class clsProxyProgress
    Public Event evProcessName(ByVal strProcessName As String)
    Public Event evDirectory(ByVal strDirectory As String)
    Public Event evCurrentFile(ByVal strCurrentFile As String)
    Public Event evFilesCompleted(ByVal intFilesCompleted As Integer)
    Public Event evFileCnt(ByVal intFileCnt As Integer)
    Public Event evRowsCopied(ByVal intRowsCopied As Long)
    Public Event evStatus(ByVal strStatus As String)

I then inherit that class in a child class.  

Public Class clsCSVDataExportSpec
    Inherits clsProxyProgress

The child class clsCSVDataExportSpec cannot "see" the events in the parent,
i.e. it cannot do:

    RaiseEvent evStatus(mstrStatus)

even though its parent class has that event.  If I try to do this in the
child class I get a compile error.

In order to get around this I created functions in the parent class
clsProxyProgress

    Public Sub mStatus(ByVal strStatus As String, ByVal blnStatusReset As
Boolean, ByVal blnStatusTimeStamp As Boolean)
        If blnStatusReset Then mstrStatus = ""

        If blnStatusTimeStamp Then
            mstrStatus = mstrStatus & vbCrLf & Now()
        End If
        If Len(mstrStatus) > 0 Then

            mstrStatus = mstrStatus & vbCrLf & strStatus
        Else
            mstrStatus = strStatus
        End If

        RaiseEvent evStatus(mstrStatus)
    End Sub

NOTICE that in the last line of the sub I raise the evStatus.  I then call
this sub from the child clsCSVDataExportSpec so that the parent class
clsProxyProgress raises the event for the child class.  I do this simply
because if I try to raise the event up in the parent class directly I get a
compile error.

The whole point of this stuff is to allow a form to sink events and display
data in text boxes on the form.

In a form class I dimension a variable for this child class:

    Private WithEvents fclsCSVDataExport As clsCSVDataExportSpec

further down I "sink" the events for this class:

    Private Sub fclsCSVDataExport_evStatus(ByVal strStatus As String)
Handles fclsCSVDataExport.evStatus
        txtStatus.Text = strStatus
        Application.DoEvents()
    End Sub

In the "Handles ..." the evStatus is a choice in the intellisense dropdown,
IOW this form's module "sees" the event that the child class
fclsCSVDataExport inherits from its parent class clsProxyProgress.  However
the sub fclsCSVDataExport_evStatus() never receives control when the
Raisevent is executed.

I SUSPECT that the issue is that the "Handles ..." needs to be "Handles
fclsProxyProgress", i.e. it needs to "handle" the parent of
fclsCSVDataExport, not fclsCSVDataExport  itself.  

fclsCSVDataExport is the actual class that performs the data export for me.
clsProxyProgress only exists to allow several different such import / export
classes inherit common events and code, and I do that so that I can
(eventually) have a generic form that dimensions a clsProxyProgress rather
than having a specific import or export class such as clsCSVDataExport or
clsCSVDataImport.

If anyone is following what I am doing and can point me to how to make this
work it would be appreciated.

Thanks,

John W. Colby
Colby Consulting
www.ColbyConsulting.com 




More information about the dba-VB mailing list