Shared variables in baseclasses

Q

Qwert

Hello,

when you have a shared variable in a baseclass, and you give it a value
through an instance of a subclass, does this shared variable and its value
still exist after you destroy all instances of that subclass?

i.e:

1: create subclass object based on base class ( base class has shared
variable ).
2: give shared variable of subclass object a value.
3: destroy subclass object.
4: create new subclass object.
5: Is shared variable of new object still that value?

I tested it and it was 'yes', but I need to know for sure,

thanks.
 
H

Herfried K. Wagner [MVP]

Qwert said:
when you have a shared variable in a baseclass, and you give it a value
through an instance of a subclass, does this shared variable and its value
still exist after you destroy all instances of that subclass?

Yes. Shared variables are completely independent from class instances.
Even 'MustInherit' classes can contain shared variables, and these variables
can be used.
 
C

Chris Dunaway

If all instances of the derived class have been destroyed, where is the
value of the variable being held? Sounds like voodoo magic to me.
Could you please elaborate on how this works?

Does the shared variable exist *before* any instances of the derived
class are created? Where does the shared variable exist?

Thanks
 
H

Herfried K. Wagner [MVP]

Chris,

Chris Dunaway said:
If all instances of the derived class have been destroyed, where is the
value of the variable being held? Sounds like voodoo magic to me.
Could you please elaborate on how this works?

Does the shared variable exist *before* any instances of the derived
class are created? Where does the shared variable exist?

It can exist before any instances of the derived classes are created.
Notice that the shared variable will be kept "alive" until the program ends.
Set it to 'Nothing' if you don't need its contents any more.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top