Let's see if I can convey this easily.. the scenario I think is fairly
standard and un-complex in theory, but currently I am having to employ..
shall we say, unusual.. methods to achieve the result.
And it's working, but it may be a) a very bad design and b) missing the
obvious/good solution to the issue.
Sorry for the post length though.. and I'm using VB6 SP5 w/MSDE 2000 on a
Win2k machine (if it matters, though this may not be the target environment
anyway).
I am looking for some quick pointers please on what I should be creating to
achieve my goal, so here's the request:
Make a server (ActiveX .exe specifically) from which clients can create
objects from. The server on behalf of these clients will contain the
necessary data access code for fetching and returning stuff.
The backend where this data resides is going to be an MSDE-hosted database
for the purpose of this scenario.
The clients are just regular little VB apps that will CreateObject() from
the server (or however they should do it).
So far so good, but the specific design issue to overcome is being able to
trigger an event in the database (such as a low stock warning or something)
and to cascade this up to the "connected" clients.
I understand I can use the sp_OA* procedures from a trigger on the database
to start this ball rolling and hook into the server (ActiveX .exe) by
creating and using some sort of Alert/Warning/Trigger object within it, but
then my issue is how to know what instances of my clients are currently
running so that I can (for example) perform a RaiseEvent within the server
to pass the alerts on.
I thought about holding some sort of collection in the server that contains
references to the server objects as each client creates them, but I fear for
creating orphaned objects (when the client unloads and sets the server
object reference to nothing, the server doesn't actually unload the object
instance still being referred to by the collection until all clients have
closed -- I think?).
So what else can I do to get around this? I have one idea and made it work,
but I'm still unhappy with it.
I basically placed a form in the ActiveX .exe which will never be displayed,
whenever a client creates a server object, that server object is then
creating a new instance of this form.
When I need to alert all of the clients, in the simplest fashion I am then
just able to get my alert object raised by the sp_OA* sprocs in the
database, which iterates through the Forms collection of the server and
raises a custom event.. this event is then caught by the server object
instances that created the form, and they too raise an event up to the
actual client.
This method using forms that are inherently members of the
globally-accessible (within the project) Forms object seems to solve my
orphaned object issue, but are there other ways? This is fine this way, but
like I said I don't know if I'm missing the obvious and/or inherently
creating a very bad (kludgy) design.. I feel that I'm not necessarily
breaking any rules per se, but I am abusing them and this is why it is a
concern.
It also has issues if, for example, in the client event handler I make it
pop up a message box or whatever, since this appears to create a blocking
situation (perhaps it should just pop up a non-modal form that is
masquerading as a kind of message box?) which means other clients don't get
to be alerted until each message box in turn is closed and the event handler
returns. Not very elegant to have to require such delicate tip-toeing by
the client developer.
So anyway, this post is getting too long so I'll end it here for now; can my
concerns be addressed or have I just chosen an unusual but workable
solution? I really want to avoid such issues as circular references to
objects, or requiring clients to have to specifically call some sort of
Destroy()/Close() method on the server, or to have the alerts being raised
cause a blocking scenario (though that is the lesser evil I can manage
regardless I think).
Thanks,
Nick
P.s. x-posted to two groups (relevant ones I hope).
Archived from group: microsoft>public>vb>enterprise