Clarification needed for custom event defined in base class

Posted by jquerijero on 02-Jun-2010 11:40

Compiler doesn't like it whan a custom event is PUBLISH from the derived class. Is this an expected behavior?

All Replies

Posted by whenshaw on 02-Jun-2010 11:49

Yes. You can publish only from the class that defines the event. If you really want to publish from a derived class, try putting a PROTECTED method that publishes the event into the class that defines the event, then call that method from your derived class.

Posted by jquerijero on 02-Jun-2010 11:50

That's what I'm doing now.

I'm just wondering why the derived class can not publish PUBLIC event defined in the base class.

Posted by whenshaw on 02-Jun-2010 12:09

PUBLIC refers only to the accessibility of the Subscribe. A tricky thing about events is that often you want the Subscribe to be public but the Publish not to be. The decision we went with (access modifier applies to Subscribe, Publish always PRIVATE) allows you to add a publishing method, like you did, to make the Publish more widely available if you want. If the access modifier for the event automatically applied to both Subscribe and Publish, there would be no way you could restrict the Publish if you needed to.

One thing we talked about was having extra syntax to allow you to specify access modes for both the Subscribe and Publish separately. We decided not to do that because we wanted to try to keep the syntax simple.

Not a perfect solution, but we're hoping that it works without too much trouble for most people.

Posted by jquerijero on 02-Jun-2010 12:37

I think you might want to have the compiler message to be more instructive than just telling the user that it can't publish since the accessibility is implied.

Posted by whenshaw on 02-Jun-2010 14:04

Is this the compiler error message you're seeing:

" Event '' cannot be published in this context. An event can be published only in the class where it is defined (and is not abstract). (15643) "

If this is not the message you see, please let Tech Support know. (Or if you are seeing this message but would like specific additional information, let Tech Support know about that, too.) Thanks.

Posted by jquerijero on 02-Jun-2010 15:11

I'm seeing that message. It just that the word "DEFINE" was used very strictly as in "WRITTEN" which got me confused.

For example: When you ask if the event is "defined" for the derived class, the answer will be yes.

I'll send a suggestion to tech support.

Posted by whenshaw on 03-Jun-2010 08:24

I see what you're saying. Maybe the message should say something like " ... only in the class that contains the DEFINE EVENT statement ... ".

This thread is closed