PDA

View Full Version : Raise event to unknown object.



EGMono
02-20-2012, 10:30 AM
Apologies if this has been covered before, but I searched the forum and read through examples and still don't quite get it...

What I am trying to accomplish is create a generic logging interface (I call it ILogger) that has one method, sWrite( sMessage As String ), that I implement in cFileLogger that writes to a file, and also in cDbgLogger that uses MsgBox to write to screen. The point of this all is that I would like to use RaiseEvent to notify any objects based on these classes, if they exist, that there is something they need to record to the log. I would like the flexibility of having 0 or more logging classes without having to change the code that broadcasts to them. For example, an error handler that logs the error, but a switch to turn on and off writing the messages to the screen.

Is this possible? Or am I totally missing the point of RaiseEvent?

Bob Phillips
02-20-2012, 02:59 PM
I don't see why you think you need RaiseEvent. I am not saying you don't, but it would appear that you just need two procedures to log the details, and switch between them based upon some value (which you would know I presume).

EGMono
02-20-2012, 06:05 PM
Maybe I don't, the point is to send a broadcast to any objects listening for it, regardless of how many loggers exist, if any. Suggestions?

mikerickson
02-20-2012, 10:49 PM
That would be easier if all the iLogger objects were collected into a iLoggers collection class.
iLoggers could have a .Trigger method that signals those objects listening.