Automatically declaring a global object 
Author Message
 Automatically declaring a global object

I'm designing a class to handle specific types of dialogs. If I
distribute a module with my class that contains a global instance of my
class (this so the user doesn't have to keep declaring a new one every
time they use it) does the user have to do this each time they want to
use my class...

   ' dlogXYZAlert is the global XYZAlert
   dlogXYZAlert = new XYZAlert

... or is there a way to do that automatically?

I know I could ask the user to initialize my class/module by calling an
initialize method on open (where I could declare dlogXYZAlert for
them), but if there's a more transparent way to do it, I'd love to
know.

Thanks.



Tue, 25 May 2004 18:14:47 GMT  
 Automatically declaring a global object
There's no more automatic way to do global initialization that I know
of, with two exceptions.  (1) If your class is really a window, then
implicit instantiation may remove the need for any such global
reference.  (2) You could make a global method which returns a
reference to your singleton instance (this seems to be the "singleton"
pattern you're using, BTW), like this:

Function XYZAlert() As XYZAlertClass
  // note, we have gXYZInstance as a private property of this module
  if gXYZInstance = nil then
    gXYZInstance = New XYZAlertClass
  end if
  return gXYZInstance
End Function

Now, users can just type "XYZAlert.DoSomething" and they'll
automatically get your global instance, which is created on the first
such call.

Cheers,
- Joe

--
,------------------------------------------------------------------.
|    Joseph J. Strout         Check out the Mac Web Directory:     |

`------------------------------------------------------------------'



Wed, 26 May 2004 00:09:16 GMT  
 Automatically declaring a global object

Quote:

> Now, users can just type "XYZAlert.DoSomething" and they'll
> automatically get your global instance, which is created on the first
> such call.

Perfect! That's exactly what I'm trying to do. Thanks.


Wed, 26 May 2004 04:28:33 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. automatically naming a global variable

2. Declaring global data for subapplications

3. Where declaring global variables when using exe + dll's with different data-dictionaries

4. Dll Declared Global Class

5. Strange behavior in C-declared global variable?

6. ?Accessing Global variables (declared in C) in ASM subroutine

7. Declaring global and static

8. How do you declare global variables?

9. global declare

10. How to declare a global varialbe

11. How to declare a global variable

12. Declaring A Function Argument As Global?

 

 
Powered by phpBB® Forum Software