Solved

Class Object Termination Problem....

Posted on 1998-07-29
8
143 Views
Last Modified: 2010-05-03
Hi there,

I've written a program that allows users to telnet to it; as each connection is made a new instance of a telnet session object is created, which is part of a collection class.

This all appeared to be working fine; objects were created for each session and then subsequently released when the client disconnected.  However, i've found a somewhat annoying bug in the program that I shall now explain.

1. Three sessions log on  - three objects are created
2. Session 1 disconnects - object is removed from collection
3. Session 1 reconnects - object is created
4. Session 1 disconnects - object is removed from collection
5. Session2 disconnects - object is removed from collection BUT - Class_Terminate event isn't fired - why???

As you can see from the above, when you perform certain actions such as these the class_terminate event isn't fired.  If, however, you then invoke any method of the class object, even if it's for a different object, then the class_terminate event is fired - it's almost as if it knows it's got to fire the event but it waits for you to do something before it continues....

Anyone got any ideas??  The class collection and objects are part of an ActiveX EXE that is used by a child programme too....

Pete
0
Comment
Question by:peterwest
  • 4
  • 3
8 Comments
 
LVL 14

Expert Comment

by:waty
Comment Utility
I think, you have to set your object to Nothing. Unless the object remains in memory

   Set yourObj = Nothing
0
 
LVL 2

Author Comment

by:peterwest
Comment Utility
I know about setting a reference to an object to nothing; this would be performed by the objects client program and not by the object itself - it doesn't explain, however, why the class_terminate event isn't been called in all circumstances.

Pete
0
 

Accepted Solution

by:
diccon earned 200 total points
Comment Utility
You don't make it clear just when Terminate events _do_ fire. It sounds to me that, if you're saying that the object's client will set to Nothing (not true - the Remove method of the collection should do that), you've probably messed up the references.
If your client is retaining a reference to a session whilst manipulating the collection, this would explain your problem.
0
 
LVL 2

Author Comment

by:peterwest
Comment Utility
diccon,

I've checked through the code and all object references are being terminated in the correct place.  I've actually found the solution to the problem after much headscratching and am a little perturbed as to why it should cause a problem - anyway i've worked a way round the problem.

I was using the BEFORE and AFTER sections of the collection.add method to insert the collection items into their appropriate locations - the idea being that I wanted to keep the collection items in order so that when I wanted to find a object key I could simply search through the collection until I found a gap - because the items were in order I could terminate the search, safe in the knowledge that the key i was going to use was unique.

Anyway, i've now re-written the routine that allocates the key for the object - it's a little more inefficient but it means the collection items don't need to be in order - it all works fine now.

Looks like the before and after parameters of the add method were causing some weird problems...

Pete


0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Expert Comment

by:diccon
Comment Utility
Before and after have no published problems that I know of. Some clue as to the code you're using would help. Are you using numeric keys in your collection?
0
 
LVL 2

Author Comment

by:peterwest
Comment Utility
Hi again,

The keys I am using are based on numeric values that are then converted to string representations using the CStr function.  I've used this method because each object relates to an element in a control array; the key ties directly to the index value of the control.

If you want I can post the code that creates an instance of the object and also the code that removes the object.

Pete

0
 

Expert Comment

by:diccon
Comment Utility
Ah, well be careful. You may have converted your keys to strings but they are passed through as variants and collections won't pay any heed to the _type_ of variant - just whether it's numeric or not (see IsNumeric).

If it is numeric, the key is taken to be an index number (position) in the collection. If it isn't, it's taken to be an access key.

Adding to a collection using Before and After with index numbers has a different effect on the resultant order from that using keys.

For example, If you have 3 items to add to a collection with keys "A", "C" and "B" respectively and you add A, then C, then B before C, the resultant order will be A-B-C as expected. If the keys were "1", "3" and "2" and you add "1" (at position 1), then "3" (at position 2) then "2" before "3" (there is no position 3 so insertion takes place at the end) and the resultant order will be 1-3-2.
0
 
LVL 2

Author Comment

by:peterwest
Comment Utility
Hi Diccon,

Well - although i've circumnavigated the problem it sounds like what you're suggesting has been the cause of the problem.

I'll bear this in mind for the future - thanks for your time.

Pete

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now