DWT event handling

Lester L. Martin II lestermartin92 at gmail.com
Sun May 18 13:48:17 PDT 2008


Frank Benoit Wrote:

> Lester L. Martin II schrieb:
> > my code is more simple
> > 
> > class listen: Listener
> >     {
> >         void delegate(Event e) func_;
> >         
> >         this(void delegate(Event e) func = null)
> >         {
> >             if(func !is null)
> >                 func_ = func;
> >             else
> >                 func_ = &this.genericHandle;
> >         }
> >         
> >         public void handleEvent(Event e) 
> >         { 
> >             func_(e); 
> >         }
> >         
> >         public void genericHandle(Event e)
> >         {
> >             Stdout("Event Accepted.").newline.flush;
> >         }
> >     }
> > 
> > (user is a declared DWT variable)
> > 
> > user.addListener(new listen(&dg));
> > 
> > (this is a function inside a class)
> > 
> > private void dg(Event E)
> > {
> >     //handle event here
> > }
> > 
> 
> I think this is just less flexible.
> This simple case would be:
> 
> user.addListener(dgListener(&dg));
> private void dg(Event E)
> {
>      //handle event here
> }
> 
> It is the same. But the template can handle _optional_ arguments that 
> are stored in a generated template class.
> 
> Well actually there is no default-handler. But i do not understand what 
> is the use of that. If you do not want a handler, why register a dummy one?
> 
> 
> 
> 

the delegate has to point to something; you cant call null(Event e); so I set it to a default one that matches our projects needs. I didn't say that it would have to be exactly like that but to us it is Flexible enought at the moment to accomplish everything we need. Extending the class to match your template and be just as flexible shouldn't be too hard (but then I'm not the one who's good at DWT, it's my friend who does that code).

Lester L. Martin II



More information about the Digitalmars-d-dwt mailing list