PC Review


Reply
Thread Tools Rate Thread

classes scope

 
 
rocco
Guest
Posts: n/a
 
      19th Oct 2008
Hello,
I hope I'm able to make this clear...

If I declare a class object into a form a module, will it "live" ONLY until
the form is loaded? Even if it is declared public?
Even if before closing the form I open another one and declare another
instance of the same object and make it point to the object previously
created?

thanks,
rocco
 
Reply With Quote
 
 
 
 
Michel Walsh
Guest
Posts: n/a
 
      20th Oct 2008
Yes for the first question. You declare a variable as public inside a form
(whatever this variable data type is an integer or a 'class'), then that
variable lives as long as the form itself lives.

If you declare, from a second source, a reference to the public variable
(property) from form FormA and then close the form FormA, then form FormA
will still live! Indeed, with COM, its reference count will not be zero
and a COM object releases its resources when its reference count is zero.
You may even have lost the 'graphical' part of FormA, but that does not mean
FormA is totally released, from memory.

Not what you ask, but may be of some interest:
If you make a real copy of (rather than keeping a reference to) the
variable, in that case, you end up with TWO clones, not TWO references to a,
one, single object, and then, closing FormA would kill one of the clone.
That being said, VBA has no pre-made syntax to make a copy rather than
making a reference, and if you really want a copy (clone) you are probably
due to use more or less complex sequence of win32 API calls. Consider that
your object can itself refer to other objects, in its variable declaration,
so, in theory, you may have to copy many objects, to effectively do what is
looking just like a single 'copy' of a single object. And while you may
think you just have to copy the children objects, think again, since the
'parent' may be referenced by a child and in this case, you do not want to
copy again the parent ( that will be a "make a copy" infinite loop). So,
indeed, copying an object is (or can be) a complex problem. That is why
using references, rather than copies, is the norm.



Vanderghast, Access MVP



"rocco" <(E-Mail Removed)> wrote in message
news:854B5500-9463-4336-BC09-(E-Mail Removed)...
> Hello,
> I hope I'm able to make this clear...
>
> If I declare a class object into a form a module, will it "live" ONLY
> until
> the form is loaded? Even if it is declared public?
> Even if before closing the form I open another one and declare another
> instance of the same object and make it point to the object previously
> created?
>
> thanks,
> rocco



 
Reply With Quote
 
rocco
Guest
Posts: n/a
 
      20th Oct 2008
Thanks!
The thing about the "cloning" knotted my brain, so i stick with reference
instead.

Thank you very much !!
rocco

"Michel Walsh" wrote:

> Yes for the first question. You declare a variable as public inside a form
> (whatever this variable data type is an integer or a 'class'), then that
> variable lives as long as the form itself lives.
>
> If you declare, from a second source, a reference to the public variable
> (property) from form FormA and then close the form FormA, then form FormA
> will still live! Indeed, with COM, its reference count will not be zero
> and a COM object releases its resources when its reference count is zero.
> You may even have lost the 'graphical' part of FormA, but that does not mean
> FormA is totally released, from memory.
>
> Not what you ask, but may be of some interest:
> If you make a real copy of (rather than keeping a reference to) the
> variable, in that case, you end up with TWO clones, not TWO references to a,
> one, single object, and then, closing FormA would kill one of the clone.
> That being said, VBA has no pre-made syntax to make a copy rather than
> making a reference, and if you really want a copy (clone) you are probably
> due to use more or less complex sequence of win32 API calls. Consider that
> your object can itself refer to other objects, in its variable declaration,
> so, in theory, you may have to copy many objects, to effectively do what is
> looking just like a single 'copy' of a single object. And while you may
> think you just have to copy the children objects, think again, since the
> 'parent' may be referenced by a child and in this case, you do not want to
> copy again the parent ( that will be a "make a copy" infinite loop). So,
> indeed, copying an object is (or can be) a complex problem. That is why
> using references, rather than copies, is the norm.
>
>
>
> Vanderghast, Access MVP
>
>
>
> "rocco" <(E-Mail Removed)> wrote in message
> news:854B5500-9463-4336-BC09-(E-Mail Removed)...
> > Hello,
> > I hope I'm able to make this clear...
> >
> > If I declare a class object into a form a module, will it "live" ONLY
> > until
> > the form is loaded? Even if it is declared public?
> > Even if before closing the form I open another one and declare another
> > instance of the same object and make it point to the object previously
> > created?
> >
> > thanks,
> > rocco

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Specify member scope in Interface Classes aaronh64@hotmail.com Microsoft Dot NET Framework 2 31st Dec 2004 04:52 PM
Specify member scope in Interface Classes aaronh64@hotmail.com Microsoft Dot NET 4 30th Dec 2004 10:28 PM
Scope, Classes and Properties paul perrin Microsoft VB .NET 6 21st Sep 2004 06:54 PM
Bug? Scope of private variables in classes John C Kirk Microsoft VB .NET 3 10th Jun 2004 02:18 PM
ADSI returning groups in Global scope and Domain local scope instead of Universal scope Maziar Aflatoun Microsoft C# .NET 1 21st Apr 2004 04:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:22 AM.