Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object Status

Status
Not open for further replies.

revanthn

Programmer
Nov 22, 2001
14
0
0
IN
Hi guys,

How can I know if an object is loaded or unloaded. I am using Visual Basic 6.0 Enterprise Edition please suggest something.


Thank You.
revanthn
 
Code:
if myobj Is Nothing then
'object not yet created
'or referece has been set to Nothing
else
'object exists
end if

is one way that you might achieve what you want.

Take care though

if you routinely define your objects such as
Code:
dim myObj as new MyClass
i.e. using the new keyword. The code above will always show that the object exists as any reference to the object, will automatically create it if it doesn't exist

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
if myobj is nothing only checks for any associations for the object and is not related to checking the very exsistance of the object.Please suggest something else.Thanx for your reply
 
Huh?

I think you're getting confused between allocating objects on the stack vs. heap-dwelling objects. VB6 does not have that distinction -- they are all COM objects and are allocated by the COM memory allocator.

If you have two object variables pointing at the same instance of an object:
Code:
Dim A As MyObject
Dim B As MyObject

Set A = New MyObject
Set B = A
Then there is no difference as far as you're concerned -- they both aren't Nothing. The fact that they're pointing at the same memory is something that you as the programmer need to be aware of (Gee, how did A's value change when I updated B?).

COM takes care of destroying the last object reference when the variables go out of scope (It uses reference counting -- when it gets to 0, it destroys the object). This is why using local variables (as opposed to global or module-level variables) is so important -- it makes sure the object gets destroyed when you no longer need it. Good programming practice also indicates that you should set your object variables to Nothing when no longer needed:
Code:
Set A = Nothing
Set B = Nothing
Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top