[AccessD] Implements vs WithEvents

Robert Gracie Subscriptions at servicexp.com
Tue Jan 13 19:47:24 CST 2004


"Hmmmmmmm, As confusion sets in, he takes and stabs himself in the chest
with his keyboard...:-)"

  I'm trying to understand why the VBA DHB is teaching that using INTERFACE
inheritance classes (by way of the Implements Keyword and such) is much
better then simply using Event, RaiseEvent, and WithEvents... The problem,
for me at least, is getting my mind around the larger concept, and knowing
which structure to use and why.

  With my very limited understanding, the way they have presented, it seems
reasonable to go this route if only to help keep control over code
execution...

I guess I just need to keep pounding away at these concepts.......



Robert Gracie
www.servicexp.com






-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of John W. Colby
Sent: Tuesday, January 13, 2004 7:54 PM
To: Access Developers discussion and problem solving
Subject: [AccessD] Implements vs WithEvents


Charlotte,

>They have somewhat different purposes.

No, they have completely different purposes.

>Implements allows you to subclass an existing object/class and give it
additional or different functionality, so you can have a class Dog and a
subclass Spaniel that has a property Retriever.

Well... true but not exactly.  My issue with that statement is the term
subclass as you use it.  Yes you are subclassing the original but ONLY the
interface.  IMHO that is almost useless

Implements is an interface ONLY inheritance, i.e. it allows (forces) you to
start with the same public data and method DEFINITION but does not actually
inherit the behaviors (methods) themselves.  I.e. the code that runs in the
class that is being subclassed is NOT inherited into the subclass.

Access' inheritance (interface) is not very useful except as a template kind
of thing.  I find it useless enough that I personally don't bother.  On the
other hand Shamil is a proponent so it must have its uses.

When you move to VB.NET (or any of the other .net languages I believe) TRUE
inheritance is available.  I.e. if you have a method with a thousand lines
of code, when you subclass that object the new object inherits that code as
well as the data.  In our Implements subclassing, you would have to cut and
paste that thousand lines of code into the subclass.  Can you say
maintenance nightmare?

>You can intercept and respond to specific events when they happen in the
object.  Did the Bark event trigger?  WithEvents
lets you find out and respond from another class/object.

Exactly correct.  One of the MAJOR shortcomings of Access / VBA (in fact VB
prior to VB.Net) is that Inheritance is virtually non-existent, and even
worse, objects other than forms don't have a built in class that you can get
at to add functionality directly to.  What WithEvents really does is allow
you to build class wrappers for objects so that you can encapsulate
behaviors (functionality) in your class.  In essence you still have two
objects, the control (or even another class or OCX) and your class, but now
you can put all of the common functionality in your class along with the
event stubs of the control/class/ocx that generates the event.

This does not get you any further down the road towards inheritance, sadly
it simply doesn't appear to be possible in Access / VBA.  But it does
provide a huge step up in encapsulation.

John W. Colby
www.ColbyConsulting.com

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Charlotte
Foust
Sent: Tuesday, January 13, 2004 4:56 PM
To: Access Developers discussion and problem solving
Subject: RE: [AccessD] =function() in .onclick


They have somewhat different purposes.  Implements allows you to
subclass an existing object/class and give it additional or different
functionality, so you can have a class Dog and a subclass Spaniel that
has a property Retriever.  WithEvents allows you to monitor the events
of an object/class.  You can intercept and respond to specific events
when they happen in the object.  Did the Bark event trigger?  WithEvents
lets you find out and respond from another class/object.

Charlotte Foust

-----Original Message-----
From: Robert Gracie [mailto:Subscriptions at servicexp.com]
Sent: Tuesday, January 13, 2004 1:45 PM
To: Access Developers discussion and problem solving
Subject: RE: [AccessD] =function() in .onclick


Hello All,
 Since I'm just learning this type of programming technique I thought I
would ask a question...

  Why not use Implements instead of WithEvents?  My limited understand
of WithEvents is that they will not return functionality unit they (the
event) has completed processing... Since I'm just at the "door" so to
speak with learning how to use and incorporate these new (to me)
programming techniques into my work, I really want to start out using
the "best" technique...


Robert Gracie
www.servicexp.com


_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com





More information about the AccessD mailing list