FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Passing nested class methods as event handlers

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
ptDDev



Joined: 09 May 2010
Posts: 1

PostPosted: Sun May 09, 2010 5:24 am    Post subject: Passing nested class methods as event handlers Reply with quote

Hi,

I am currently using the DFL from the latest monthly update (02.May.2010), with D version 2.045. For the most part, it seems to work fine. Smile

I just have a minor request. While the event handling API is already quite simple, I'm wondering if it could be adapted to support calls to methods from nested classes. It would be interesting to be able to organize the event handlers in this way:

Code:

class MyForm : dfl.form.Form
{
// ...
   class MyEvents
   {
      class Toolbar
      {
      // ...
      }
      class Menu
      {
         class File
         {
             void Quit(Object o, EventArgs args) { MyForm.close(); }
         // ...
         }
         class Help
         {
            void About(Object o, EventArgs args) { /*show something*/ }
         }
      }
   }
}


This would allow to write the event attachment to something like:
Code:
quitMenuItem.click ~= &MyEvents.Menu.File.Quit;

Which is more human readable, and any good source code editor makes very easy to locate.

Unless I'm missing something, when I try to compile this, the compiler complains that the function reference I am trying to pass should be a member function of "this" (which means MyForm, I would assume) instead of MyForm.MyEvents.Menu.File.Quit. Is this a real restriction that's imposed, or is there a way to bind the event to any class method?

For the time being, I'm using the VB-ish syntax with underscores instead (Menu_File_Quit). But it still pollutes the MyForm class with event methods IMHO.

In the way of thanking you for this very useful library (hope to see that Linux/GTK port soon), and Walter Bright for this wonderfully pragmatic language, I hope to see this question answered soon.

Kind regards.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group