Scope of a Class

Jay1b

Contributor
Joined
Aug 3, 2003
Messages
640
Location
Kent, Uk.
Hi

I'm having problem getting a class to be referenced from several forms.

The class in question is a simple class to log output to a file. So at any point i can write

Visual Basic:
LogEvent("12 rows were returned")

and this will be written out to a log file. I would like to instigate the class when the main screen loads and have every other form call this class with just using the above code. Can someone please tell me how i can do this?

Thanks

Jay
 
You could build the log class using static methods if you only need one log application wide. Then you would be able to access it like you want:
Visual Basic:
ClassName.LogEvent("Hello World")
 
option/idea 1. Make it a static class with a LogEvent(string) method?

option/idea 2. Initialize the Logger class in your main form (with a file name, etc) and pass it to each of the classes that might use it.

option/idea 3. Do the same as 2, but pass a delegate to the LogEven(string) method instead of the Logger Class.
 
Thanks guys. I've finally got my head around sharing classes. Or at least i think i have.

I'm going to be using one of two methods.

1) For classes such as the LogEvent one, which will be accessed from all frames, i'll use shared
2) For classed which will just be used between 2 frames, i'll pass the instance of the class between the two frames.

Thanks
 
Back
Top