ptDDev
Joined: 09 May 2010 Posts: 1
|
Posted: Sun May 09, 2010 5:24 am Post subject: Passing nested class methods as event handlers |
|
|
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.
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. |
|