Event handling

bobef bobef at abv-nospam.bg
Fri Mar 28 06:47:30 PDT 2008


Maybe you could use opCall to make things shorter to write?

Frank Benoit Wrote:

> I think about how to do the event handling more D like, but also to 
> avoid adding/changing code in the ported code.
> 
> The dwt from Shawn made this possible:
> 
> table.addListener(
> 	DWT.Selection,
> 	&myHandler,
> 	&myData
> 	);
> 
> + use of delegates
> + optionally add data that is passed to the delegate
> - data must an "Object"
> - adds code into the dwt
> 
> Now i think about adding this new class template to dwt.widgets.Listener:
> 
> /// start of addition to dwt.widgets.Listener
> class DgListenerT( T... ) : Listener {
>      alias void delegate(Event, T) ADel;
>      ADel dg;
>      T t;
>      public this( ADel dg, T t ){
>          this.dg = dg;
>          this.t = t;
>      }
>      public void handleEvent( Event e ){
>          dg(e, t);
>      }
> }
> alias DgListenerT!() DgListener;
> /// end of addition to dwt.widgets.Listener
> 
> 
> table.addListener(
> 	DWT.Selection,
> 	new DgListener( &myHandler )
> 	);
> table.addListener(
> 	DWT.Selection,
> 	new DgListenerT!( int )( &myHandler, 23 )
> 	);
> 
> + use of delegates
> + optionally add data that is passed to the delegate
> + data count and types are not fix
> + adds only additional class outside existing classes
> + no dwt internals need to be changed and maintained
> - need heap allocate the DgListenerT instance
> 
> Are there more arguments pro/cons?
> Would you prefer another solution?



More information about the Digitalmars-d-dwt mailing list