[AccessD] Forced logout

John W. Colby jwcolby at colbyconsulting.com
Tue Feb 10 22:44:24 CST 2004


Well, I have a general shutdown system working that raises events for
shutdown warnings as well as the shutdown itself.  I thought you folks who
are into RaiseEvents and WithEvents might be interested in this..

I am testing with THREE shutdown records, i.e. two at specific times, and
one that is just a forced shutdown.  In order to do this I use a clsShutDown
that process a single shutdown record and handles all aspects of that
specific shutdown, calculating when to issue warnings, opening a cancelable
form, raising a warning or shutdown event and so forth.

I also have a supervisor class which has a collection.  The supervisor has a
class factory that creates a clsShutdown instance for each record in the
table, and then stores a pointer to that shutdown class instance in this
collection.

Remember that the clsShutdown can raise two different events, one a
"warning" event when the warning is issued to the user, the other a
"Shutdown" event when it is actually time to shut down.

Since the Supervisor class contains the clsShutdown instances in it's
collection, how do we sink the events that the clsShutdown instances raise?

The answer is to have a class global variable of a clsShutdown in the
supervisor class' header.  The timer tick of the controlling form calls a
TimerTick method of the supervisor class.  That method then iterates the
collection of clsShutdown instances SETTING THE SUPERVISOR CLASS GLOBAL TO
EACH SHUTDOWN INSTANCE POINTER IN TURN.

Since that supervisor class global variable was dimensioned WithEvents it
can sink an event from whatever class is currently being pointed to.  Thus
we "switch in/out" an instance of clsShutdown, call a method of that
specific instance telling it that it is time to see if we should issue a
warning or perform a shutdown.  THAT INSTANCE then MAY (if it is time) RAISE
one of it's two events which is sunk in the supervisor class.  The
clsShutdown event passes a parameter in it's RaiseEvent with it's name, so
now the classSupervisor knows what class instance raised the event.  In fact
the supervisor simply RAISES IT'S OWN EVENT by the same name and passes the
parameter along to whoever is sinking the supervisor's events.

What this means is that the supervisor can sink it's child class' events,
one class at a time as it iterates it's child class collection.  As the
child class' events fire, the supervisor class sinks it and turns right
around and raises it's own event passing along the parameters from the child
class that originally raised the event.

The object sinking the supervisor class' events can do what it wants (or
nothing) with the events, but it has been notified.

I've been wondering for awhile whether I could manage to sink events for
classes held in a collection and this seems to work very nicely.

The code of interest is dead simple:

In the supervisor class header:

*******

Private mcolClsShutdown As Collection

Private WithEvents mCurrentClsShutdown As clsShutdown

Public Event ShutdownWarning(strShutdownName As String,
lngSecondsTillShutdown As Long)
Public Event Shutdown(strShutdownName As String)

Public Function TimerTick()
Dim lclsShutdown As clsShutdown
    'Cycle through all the classes in the collection, setting each to the
    'module level global variable in turn.
    '
    'This SHOULD allow me to sink each classes' events here in this class
    'and propagate it on to the user of this supervisor class
    '
    For Each lclsShutdown In mcolClsShutdown
        Set mCurrentClsShutdown = lclsShutdown
        mCurrentClsShutdown.CheckShutdown
    Next lclsShutdown
End Function
Private Sub mCurrentClsShutdown_Shutdown(strShutdownName As String)
    RaiseEvent Shutdown(strShutdownName)
    MsgBox "Shutdown: " & strShutdownName
End Sub
Private Sub mCurrentClsShutdown_ShutdownWarning(strShutdownName As String,
lngSecondsTillShutdown As Long)
    RaiseEvent ShutdownWarning(strShutdownName, lngSecondsTillShutdown)
    MsgBox "ShutdownWarning: " & strShutdownName
End Sub

*******

Of course there is initialize / terminate code etc.  This is JUST the code
that iterates the child class collection, tickles each child class to see if
it is time to raise it's event, then sinks these events and propagates them
along.

I thought this was a pretty cool (and simple) way to handle this situation.

I am not finished debugging the particulars of "forced shutdown" and "time
back in", but I will post the demo to my web site when I get that finished.
This stuff is working though, using a single "control form" to raise the
timer ticks and sink the supervisor class events.

John W. Colby
www.ColbyConsulting.com




More information about the AccessD mailing list