Home End User

Determining if an Event exists for a Component

edited January 2003 in End User
I was wondering if there was a way to tell if an event was available for a
specific component in code. For example the following code returns the
OnPrint event handler for the ppLabel1 component if once exists:

lEventHandler:= lCodeModule.GetEventHandlerForComponent(ppLabel1,'OnPrint')

If one does not exist then following code will create an OnPrint event
handler for ppLabel1:

lEventHandler:= lCodeModule.CreateEventHandler(ppLabel1,'OnPrint');

However, if I attempt to create an OnFax event handler for ppLabel1 I
receive an Access Violation because OnFax is not an available event for
ppLabel1.

lEventHandler:= lCodeModule.CreateEventHandler(ppLabel1,'OnFax');

What I'd like to know is if there is a way to determine if an event is
available for a specific component or do I need to *know* that it is
available prior to trying to create it? Could I simply do a try..except
around the above code as follows:

try
lEventHandler:= lCodeModule.CreateEventHandler(ppLabel1,'OnFax')
except
ShowMessage('Event does not exist');

Thanks,
Scott

Comments

This discussion has been closed.