When the component is double-clicked, the Edit method of the component editor is called. By default, the Edit method executes the first command added to the context menu. Thus, in the previous example, double-clicking the component executes the DoThis command.
While executing the first command is usually a good idea, you may want to change this default behavior. For example, you can provide an alternate behavior if
procedure TMyEditor.Edit; var FontDlg: TFontDialog; begin FontDlg := TFontDialog.Create(Application); try if FontDlg.Execute then MyComponent.FFont.Assign(FontDlg.Font); finally FontDlg.Free end; end;
void __fastcall TMyEditor::Edit(void) { TFontDialog *pFontDlg = new TFontDialog(NULL); pFontDlg->Execute(); ((TMyComponent *)Component)->Font = pFontDlg->Font; delete pFontDlg; }
procedure TMyEditor.EditProperty(PropertyEditor: TPropertyEditor; Continue, FreeEditor: Boolean) begin if (PropertyEditor.ClassName = 'TMethodProperty') and (PropertyEditor.GetName = 'OnSpecialEvent') then // DefaultEditor.EditProperty(PropertyEditor, Continue, FreeEditor); end;
void __fastcall TMyEditor::EditProperty(TPropertyEditor* PropertyEditor, bool &Continue, bool &FreeEditor) { if (PropertyEditor->ClassNameIs("TMethodProperty") && CompareText(PropertyEditor->GetName, "OnSpecialEvent") == 0) { TDefaultEditor::EditProperty(PropertyEditor, Continue, FreeEditor); } }
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|