Delegates and classes for custom code.

Chris Katko ckatko at gmail.com
Tue Apr 17 03:55:55 UTC 2018


What I want:

class viewport_t
   {
   int x,y,w,h;
   }

class dialog_t
   {
   int x,y;

   this( int x, int y, delegate void (viewport_t) on_draw )
     {
     this.x = x;
     this.y = y;
     this.execute = execute;
     }

   void draw_text(string text)
     {
     }

   delegate void (viewport_t) on_draw;
   }

void function()
   {
   viewport_t v;
   dialog_t (15, 15,
         delegate void (viewport_t)
           {
           draw_text("hello world"); //calls dialog_t function
           }
         )
   }

Is this possible? Pass to a class, the code to run. But the code 
has to somehow know about the class methods.

I don't think you can pass "dialog_t.this" as it's being 
constructed!


More information about the Digitalmars-d-learn mailing list