RAD Studio |  |

Implementing Commands

When the command provided by GetVerb is selected in the designer, the ExecuteVerb method is called. For every command you provide in the GetVerb method, implement an action in the ExecuteVerb method. You can access the component that is being edited using the Component property of the editor.

For example, the following ExecuteVerb method implements the commands for the GetVerb method in the previous example.

Copy Code

    procedure TMyEditor.ExecuteVerb(Index: Integer);
    var
      MySpecialDialog: TMyDialog;
    begin
      case Index of
        0: begin
             MyDialog := TMySpecialDialog.Create(Application);       { instantiate the editor }
             if MySpecialDialog.Execute then;                 { if the user OKs the dialog... }
               MyComponent.FThisProperty := MySpecialDialog.ReturnValue;   { ...use the value }
             MySpecialDialog.Free;                                       { destroy the editor }
           end;
        1: That;                                                       { call the That method }
      end;
    end;

Copy Code

    void __fastcall TMyEditor::ExecuteVerb(int Index)
    {
    switch (Index)
    {
    case 0:
    TMyDialog *MySpecialDialog = new TMyDialog();
    MySpecialDialog->Execute();
    ((TMyComponent *)Component)->ThisProperty = MySpecialDialog->ReturnValue;
    delete MySpecialDialog;
    break;
    case 1:
    That();  // call the "That" method
    break;
    }
    }

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!