comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Event handler as an object method ??
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Event handler as an object method ?? [message #41660 is a reply to message #41601] Thu, 11 November 2004 06:26 Go to previous messageGo to previous message
Benjamin Hornberger is currently offline  Benjamin Hornberger
Messages: 258
Registered: March 2004
Senior Member
David Fanning wrote:
> Antonio Santiago writes:
>
>
>> Hi,is there a reason why an object method can't be use as an event handler?
>
>
> No reason at all. In fact, it is only short step
> now before you realize widgets should be objects. :-)
>
>> I just created an object that "contains" a WIDGET_DRAW. I'd like that
>> the event ocurred on WIDGET_DRAW was handled by a method of my class,
>> but EVENT_FUNCTION and EVENT_PRO keywords not accpet a method.
>>
>> The solution i have adopted is to catch the event of WIDGET_DRAW outside
>> of the object (on a WIDGET_BASE where i put the object (realy de
>> WIDGET_DRAW)) and redirect it to the method i want
>> (MyObject->EventHandler), but this is an ugly solution.
>
>
> In the absence of help from RSI, most solutions are more
> or less ugly. The solution I usually adopt is to have
> all events go to a generic event handler. In the event
> handler, a "command" structure is extracted from the user
> value of the widget that caused the event. The "command"
> is an anonymous structure containing an "object" and
> a "method" field. All the event handler does is extract
> the command structure and use CALL_METHOD to call the
> method field on the object field, passing the event structure
> as a parameter to the "event handler method".
>
> To make this work, every widget that is going to generate
> an event has a "command" structure stored in its user value:
>
> drawID = Widget_Draw(tlb, XSize=400, YSize=400, $
> UValue={object:myobject, method:'MyEventHandlerMethod'})
>
> The generic widget event handler does this:
>
> Widget_Control, event.id, Get_UValue=cmd
> Call_Method, cmd.method, cmd.object, event
>
> In my Catalyst Library, all widgets are objects and the
> "fields" of the "event structure" all point to objects
> as well, so this slight of hand feels a little more
> natural. Instead of using Event_Pro or Event_Func
> to direct events, you can use an Event_Method keyword
> to define the appropriate method to handle the event
> If an event method is not specified, we use a EventHandler
> method that is always associated with an widget object.
>
> Cheers,
>
> David
>


Is it right that in this case (as David proposes), you don't need the

widget_control, event.top, get/set_uvalue=info, /no_copy

any more to pass the widget's (now object's) internal variables around?
Instead, you can just access the members of the self structures in the
"event handler"? That would be nice...

Benjamin
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: f77 unformatted file reading error
Next Topic: UTM mapping problems

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Tue Oct 14 17:21:39 PDT 2025

Total time taken to generate the page: 3.60373 seconds