[dba-VB] inheriting events

jwcolby jwcolby at colbyconsulting.com
Wed Jan 2 12:39:33 CST 2008

Sorry guys, I figured it out.

Basically I have a base class (clsProxyProgress) whose sole reason for its
existence is to raise events for derived classes.

I have one (at the moment) derived class (clsCSVDataExportSpec) which can
then use its parent clsProxyProgress to raise events for it.
clsCSVDataExportSpec supervises EXPORTING data.

I have a frmProxyProgress whose sole purpose is to sink the events raised
via clsProxyProgress and display progress data for classes derived from
clsProxyProgress - clsCSVDataExportSpec in this case.  IOW it is
clsCSVDataExportSpec that wants to display status information, and it does
so via clsProxyProgress (its parent).

I have a supervisor class that creates instances of clsCSVDataExportSpec.  I
may have 1 or 5 different CSV Exports happening, and the supervisor class
loads and starts them running.  These instances of clsCSVDataExportSpec are
run periodically which is why there may be 1 or N, it just depends on
whether it is time to run a specific instance.

Each instance of clsCSVDataExportSpec gets data that tells it whether or not
to open a display form frmProxyProgress to display its progress in.

clsCSVDataExportSpec does not NEED a progress form in order to function, it
simply displays its progress data in a frmProxyProgress instance if it is
told to do so.  In fact it simply INSTANTIATES a frmProxyProgress if it is
told to do so.  It always raises the events that would be displayed in
frmProxyProgress even if it does not have a display form open to use.

clsProxyProgress and frmProxyProgress can also be used for
clsCSVDataImportSpec.  clsCSVDataImportSpec is a class which supervises
IMPORTING data.  There may be 1 or N copies of clsCSVDataImportSpec.
Likewise clsCSVDataImportSpec can be told to display it's progress in an
instance of frmProxyProgress.  There are also two flat file process classes
that can use clsProxyProgress and frmProxyProgress. Each of them can have 1
or N instances running.  As you can see there can be nothing running or
there can be a dozen different CSV or FlatFile imports or exports running,
all at the "same" time.  Each can display a progress or not.

So the point here is that by creating clsProxyProgress and frmProxyProgress,
I have a form that sinks events from clsProxyProgress, and four different
Flat/CSV Import/Export classes that inherit clsProxyProgress.  Because they
all inherit the same class, they can all raise the same events up in the
base class, but more importantly I now have just one proxy class and one
proxy form that handles all of the raising / sinking of these events and
displaying the status in form instances.

The key to get it all working is that I needed to know that I could pass a
derived class into a declaration of a base class in the New() sub.

In the proxy FORM:

'Dimension a base class variable WithEvents
private WithEvents mclsProxyProgress  as clsProxyProgress
'In New() receive a base class instance
sub new( lclsProxyProgress as clsProxyProgress)
	'Set the module level variable = to the instance pointer passed in
to new()
	mclsProxyProgress = lclsProxyProgress
end sub

'Sink events for the base class here and perform some action (display a
status for example)
sub mslcProxyProgress_SomeEventSink(strStatus as string)
	txtStatus.text = strStatus
end sub

In the base class:
'Dimension a form variable to use to display the status
private mfrmDisplay as form
'Open a form and pass in a pointer to me
sub OpenDisplayForm()
	set mfrmDisplay = new frmProxyProgress(me)
end sub

NOTICE that I passed in a pointer to the DERIVED class but the form's New()
expects a variable of the Base class.  That works, and that is what I was
stumbling over.  I did not realize that VB.Net would dynamically cast a
derived class into a base class in this fashion.

With all this in place, I can have 1 to N instances of many different
derived classes (siblings) of the base class clsProxyProgress.  All the
derived classes (siblings) can use the same form (but not the same INSTANCE
of that form) to display its progress.  Each instance of a derived class can
have its own instance of a status form and display its status in that form

Sometimes when I don't understand what I am doing, I can't explain what I
don't understand well enough to get help in understanding it.

Or MAYBE (as William is wont to say) I am just obtuse.

I think I now need to go back into the base class and declare it MustInherit
and declare all of the methods ... uh... friend?  Or protected?  Another
thing that I do not understand at all really.

John W. Colby
Colby Consulting
-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust
Sent: Wednesday, January 02, 2008 12:27 PM
To: dba-vb at databaseadvisors.com
Subject: Re: [dba-VB] inheriting events

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 

More information about the dba-VB mailing list