Global Class Decleration 
Author Message
 Global Class Decleration

I am going to ask a very lazy question because I really don't have the time
to test it.  I created a class that holds all of the object's names(forms,
tables, queries etc) for my application.  The reason I did this is so that I
can keep up with all of the object names in one place and also so that I can
take advantage of the intelliwrite feature in Access97 for faster coding.
What I did is I declared the object as global oAppObj as New cAppObj.  Does
this mean that a new instance of the object is created each time I reference
the object or is it one time only, the first time the object is referenced.
Of course if it's a new class instance each time then wouldn't this create a
memory leak and eventually bring the app to a stand still?  Also, I did not
want to call the initialization routine for the object at the start of the
program and hope that my program does not crash because I noticed that when
it does crash the instance of the object then disappears.  Inputs, ideas
discussions are all extremely welcomed.  I just started using classes about
a month ago and I am still learning a lot about them.  BTW classes are the
most beneficial and intriguing tool that I have learned in Access.  I denied
learning them for a long time but now I would not use anything else but.
Like I said, I am still gathering a lot of information on them and sorting
through the concepts.  I try to read Ken's articles whenever I get a chance,
and now I know why those guys are trying to push the concept so hard.  You
will only know the real value if you take the time to learn them.

Thanks,

Alan



Sun, 20 Aug 2000 03:00:00 GMT  
 Global Class Decleration

Quote:
>What I did is I declared the object as global oAppObj as New cAppObj.  Does
>this mean that a new instance of the object is created each time I reference
>the object or is it one time only, the first time the object is referenced.

The object is created the first time it is referred to -- any
references to its properties or methods. There is only one instance of
'oAppobj' at any given time.

The problem with this is that it's not the most efficient way to do it
from VBA's standpoint. If you use this syntax, VBA has NO WAY of
knowing what line of code might cause the object to be instantiated.
Depending on if-tests, or the order of execution of procedures etc.
any reference to a property or method might be the first one to the
object. Therefore VBA needs to wrap a test around every reference to
the object to test whether it has been instantied yet or not.

For the simple case where you're creating and destroying the object in
a single proc this isn't so bad:

dim dog as new CDog

with dog
  .name = "fido"
  .legs = 3
  .bark()
end with

Still, I almost always would code it this way:

dim cat as CCat
Set cat = new CCat

with cat
  .name = "Puff"
  .livesleft = 2
  .meow()
end with

In this case, VBA only has to insert the initialization code on the
'set cat = new CCat' line.

-- Jim Ferguson, FMS
   http://www.fmsinc.com



Sun, 20 Aug 2000 03:00:00 GMT  
 Global Class Decleration

Quote:
>  .legs = 3

Poor dog... why, oh why this atrocity :-)

my apologies for this digression, but couldn't help it
--
Just my $.001
Dev Ashish



Sun, 20 Aug 2000 03:00:00 GMT  
 Global Class Decleration

Quote:
>>  .legs = 3

>Poor dog... why, oh why this atrocity :-)

He ran into the wrong CCat...

-- Jim Ferguson, FMS
   http://www.fmsinc.com



Sun, 20 Aug 2000 03:00:00 GMT  
 Global Class Decleration

LOL.... try using the CPayback class, it apparently sets the cats hair to
Null.

Michael


Quote:
>>>  .legs = 3

>>Poor dog... why, oh why this atrocity :-)

>He ran into the wrong CCat...

>-- Jim Ferguson, FMS
>   http://www.fmsinc.com



Fri, 25 Aug 2000 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Global Decleration - Problem.

2. if userform has global scope, it activates document that instantiated the class

3. problem with class in global.asax.vb file

4. Global class for control settings

5. Question on Global Variables and Classes

6. IS there a way to create a global class

7. GlobalMultiUse (global class instances)

8. Load a class from the global.asa

9. Global Class - needs help

10. Object passing and global class.

11. Load a class from the global.asa

12. Global Multiuse Instancing of Class...please explain

 

 
Powered by phpBB® Forum Software