TKD AddProtocolCommand example

DaveG via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed May 14 14:23:01 PDT 2014


Hello

Could someone provide an example how to use addProtocolCommand?

The following is how I would expect it to work:

import tkd.tkdapplication;   // Import Tkd.

class Application : TkdApplication                       // 
Extend TkdApplication.
{

     private void exitCommand(CommandArgs args)           // 
Create a callback.
     {
          this.exit();                                     // Exit 
the application.
     }

     private void saveMeCommand(CommandArgs args)
     {
         new MessageDialog(this.mainWindow,"Saving...")
             .setMessage("Bye")
             .show();
     }

     override protected void initInterface()              // 
Initialise user interface.
     {

         
this.mainWindow.addProtocolCommand(WindowProtocol.saveYourself, 
&this.saveMeCommand);

         auto frame = new Frame(2, ReliefStyle.groove)    // 
Create a frame.
             .pack(10);                                   // Place 
the frame.

         auto label = new Label(frame, "Hello World!")    // 
Create a label.
             .pack(10);                                   // Place 
the label.

         auto exitButton = new Button(frame, "Exit")      // 
Create a button.
             .setCommand(&this.exitCommand)               // Use 
the callback.
             .underlineChar(1)
             .pack(10);                                   // Place 
the button.

     }

}

void main(string[] args)
{
     auto app = new Application(); // Create the application.
     app.run();                                           // Run 
the application.
}


I get the following when I try to compile:

tkd\window\window.d(426): Error: undefined identifier 
CommandCallback
main.d(21): Error: template 
tkd.window.window.Window.addProtocolCommand cannot deduce 
function from argument types !()(WindowProtocol, void 
delegate(CommandArgs args)), candidates are: 
tkd\window\window.d(426):        
tkd.window.window.Window.addProtocolCommand(this T)(string 
protocol, CommandCallback callback)

If I comment out the line where I try to add the command, it 
compiles and runs fine:




More information about the Digitalmars-d-learn mailing list