www.digitalmars.com         C & C++   DMDScript  

D - Event (Dig)

reply "Phill" <phill pacific.net.au> writes:
Does anyone know how to get the Object
source of an Event, in Dig. ie:

Button b;

//later on

with(b = new Button("1")){
    onClick(handleEvent());
    }

// later on

handleEvent(Event event){
         //now how do I get the Object source and
         // string from the button from the parameter
     }

I have made a simple calculator with 18 buttons,
at the moment I have a function to handle each buttons
event ie: 18 Event functions.

Code attached.

Phill.
Jan 23 2004
parent reply Burton Radons <loth users.sourceforge.net> writes:
Phill wrote:
 Does anyone know how to get the Object
 source of an Event, in Dig. ie:
 
 Button b;
 
 //later on
 
 with(b = new Button("1")){
     onClick(handleEvent());
     }
 
 // later on
 
 handleEvent(Event event){
          //now how do I get the Object source and
          // string from the button from the parameter
      }
 
 I have made a simple calculator with 18 buttons,
 at the moment I have a function to handle each buttons
 event ie: 18 Event functions.
 
 Code attached.

I'm afraid that while that was always in the plan, I never got around to it. However, it's easy to do what you want in this case. Just have something like this: class AppendFunction { char [] text; /**< Text to append. */ this (char [] text) { this.text = text; } void event (Event event) { ed.text (append (ed.text (), text)); } } void doView () { int c, r = 1; void createNumericButton (char [] text) { with (new Button (this)) { caption (" &" ~ text ~ " "); grid (c ++, r, 1, 1); sticky ("<>^v"); bordered (true); onClick.add (&(new AppendFunction (text)).event); } } void nextRow () { c = 0, r ++; } createNumericButton ("1"); createNumericButton ("2"); createNumericButton ("3"); nextRow (); createNumericButton ("5"); createNumericButton ("6"); createNumericButton ("7"); nextRow (); createNumericButton ("8"); createNumericButton ("9"); createNumericButton ("0"); nextRow (); ... }
Jan 25 2004
parent "Phill" <phill pacific.net.au> writes:
Thanks Burton!

That works great, it will also be a great help in
the future.

Phill.


"Burton Radons" <loth users.sourceforge.net> wrote in message
news:buvvru$1l98$1 digitaldaemon.com...
 Phill wrote:
 Does anyone know how to get the Object
 source of an Event, in Dig. ie:

 Button b;

 //later on

 with(b = new Button("1")){
     onClick(handleEvent());
     }

 // later on

 handleEvent(Event event){
          //now how do I get the Object source and
          // string from the button from the parameter
      }

 I have made a simple calculator with 18 buttons,
 at the moment I have a function to handle each buttons
 event ie: 18 Event functions.

 Code attached.

I'm afraid that while that was always in the plan, I never got around to

 However, it's easy to do what you want in this case.  Just have
 something like this:

     class AppendFunction
     {
         char [] text; /**< Text to append. */

         this (char [] text)
         {
             this.text = text;
         }

         void event (Event event)
         {
             ed.text (append (ed.text (), text));
         }
     }

     void doView ()
     {
        int c, r = 1;

        void createNumericButton (char [] text)
        {
           with (new Button (this))
           {
              caption (" &" ~ text ~ " ");
              grid (c ++, r, 1, 1);
              sticky ("<>^v");
              bordered (true);
              onClick.add (&(new AppendFunction (text)).event);
           }
        }

        void nextRow ()
        {
           c = 0, r ++;
        }

        createNumericButton ("1");
        createNumericButton ("2");
        createNumericButton ("3");
        nextRow ();
        createNumericButton ("5");
        createNumericButton ("6");
        createNumericButton ("7");
        nextRow ();
        createNumericButton ("8");
        createNumericButton ("9");
        createNumericButton ("0");
        nextRow ();
        ...
     }

Jan 25 2004