pointeman
asked on
Class Library Delegate and Event Issues?
I usually built a Class Libary within a Windows Forms project. I can test the class by using buttons and textboxes. I send the 'Status' messages to Form1 using a Delegate and Event as illustrated in the code example below. The problem arises when deploying the Class Libarary to be used with another executable. The unused Delegate causes an 'Object Reference' error if it's not instanctiated in the new executable. I want the option for class library status message returns if needed, but don't want to demand the delegate instanciation.
[class library (.dll)]
public delegate void JobManagerStatusEventHandl er(string statusMessage);
public static class JobSetup
{
public static event JobManagerStatusEventHandl er StatusMessage;
}
[class library (.dll)]
public delegate void JobManagerStatusEventHandl
public static class JobSetup
{
public static event JobManagerStatusEventHandl
}
then, you must initialice the object in your dll
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you must create the object, because the class is static is created in memory and you must create one instance for related objects
http://msdn.microsoft.com/en-us/library/79b3xss3%28v=vs.80%29.aspx
http://msdn.microsoft.com/en-us/library/79b3xss3%28v=vs.80%29.aspx
ASKER
Q, Anyway to use a cool ?? operator instead?
StatusMessage(?? : "Hello World!");
StatusMessage(?? : "Hello World!");
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Cool, thanks again