Link to home
Start Free TrialLog in
Avatar of pointeman
pointemanFlag for United States of America

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 JobManagerStatusEventHandler(string statusMessage);

    public static class JobSetup
    {
        public static event JobManagerStatusEventHandler StatusMessage;
    }
Avatar of Haver Ramirez
Haver Ramirez

then, you must initialice the object in your dll
SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of pointeman

ASKER

Q, Anyway to use a cool ?? operator instead?

        StatusMessage(??  : "Hello World!");
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Cool, thanks again