DWUTKA at marlow.com
DWUTKA at marlow.com
Tue Jun 13 12:24:31 CDT 2006
True, but it works either way. Drew -----Original Message----- From: John W. Colby [mailto:jwcolby at colbyconsulting.com] Sent: Tuesday, June 13, 2006 11:58 AM To: 'Access Developers discussion and problem solving' Subject: Re: [AccessD] Class Rebuttal was: Basic Unbound Form ... It still doesn't have to be global though. Private mMyClass As MyClass Function cMyClass() as MyClass set cMyClass = mMyClass End function Now it is global without anybody in the world able to (for example) "clean it up" by setting the pointer to null. I actually use this kind of thing for a "messaging" system internal to the application. A message class: Public Event Message(varFrom As Variant, varTo As Variant, _ varSubj As Variant, varMsg As Variant) Public Event MessageSimple(varMsg As Variant) Function Send(varFrom As Variant, varTo As Variant, _ varSubj As Variant, varMsg As Variant) RaiseEvent Message(varFrom, varTo, varSubj, varMsg) End Function Function SendSimple(varMsg As Variant) RaiseEvent MessageSimple(varMsg) End Function By instantiating the class, anyone can send a message and anyone (class) can receive a message. In a module: Private mclsMsg as clsMsg Function cMsg as clsMsg() if mclsMsg is nothing then set mclsMsg = new clsMsg endif set cMsg = mclsMsg End function Then someone sends a message: cmsg.SendSimple "Hello there" Anyone sinking messages on this message channel now receives this message. Or sends an "email type" message cmsg.Send "frmClaim", "frmAccounting", "Claim Payment", "Some payment data" Everyone on the channel receives the message and tests to see if the message is for them, from someone they want to receive messages from etc. And of course any class can sink an event so it doesn't even have to be a form which receives the message. And of course, because the message is a variant, anything including a pointer to a form or pointer to a control can be sent to the receiving class. I use this to pass a control to a calendar form, so that the calendar form can return the data directly back to the control. The calendar listens on a channel and anyone can open the form (modal), pass the control to have the data placed in, and when control returns to the caller the control is populated with the date. JWC -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of DWUTKA at marlow.com Sent: Tuesday, June 13, 2006 12:24 PM To: accessd at databaseadvisors.com Subject: Re: [AccessD] Class Rebuttal was: Basic Unbound Form ... And where do you declare the object? Let's say MyClass has an event. Now I have three forms that need to see that event. Dim withevents MyClassObject as MyClass That would go in the declarations, but how to you get all three forms to see the same event? If each form had this in the Form Load event: Set MyClassObject=New MyClass Now each will see AN event when it is raised, but if form1 triggers the event, it's going to get the event from it's instance of MyClass. None of the other forms will. However, if MyClass was a global variable: Public GlobalMyClass As MyClass And the Load events had: Set MyClassObject=GlobalMyClass Now, when the event is triggered all three forms see the event. Drew -----Original Message----- From: Charlotte Foust [mailto:cfoust at infostatsystems.com] Sent: Tuesday, June 13, 2006 10:49 AM To: Access Developers discussion and problem solving Subject: Re: [AccessD] Class Rebuttal was: Basic Unbound Form ... Huh? What are you declaring globally? You raise an event from the class and sink it in the other objects. What does a global have to do with that? Charlotte Foust -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com