[dba-VB] inheriting events

Charlotte Foust cfoust at infostatsystems.com
Wed Jan 2 11:27:26 CST 2008


I'm not sure I understand what you're trying to do, John.  Your
clsdDSVDataExportSpec inherits the methods and properties of the class
clsProxyProgress, it doesn't inherit things happening to
clsProxyProgress.   We have a TransferHelper class which doesn't inherit
anything.  We have classes for Import and Export that are declared as
Public MustInherit, with all their methods and properties declared as
protected.  Then we have specific transfer method classes that inherit
the MustInherit classes and that handle the specific operations required
for a particular type of import or export.  The TransferHelper class has
shared methods and properties, so we can call them by code like
TransferHelper.ImportCSV(args).  

I don't see what you're trying to do by raising a "status" event.  Are
you logging the work?  We use a separte EventLogItem class to wrap the
creation of event log items.

Charlotte Foust 

-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Monday, December 31, 2007 2:00 PM
To: dba-vb at databaseadvisors.com
Subject: [dba-VB] inheriting events

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