Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ray Konopka Developing Custom VCL and VCL.NET Component Designers DevCon 2005 -- Course No: 3146.

Similar presentations


Presentation on theme: "Ray Konopka Developing Custom VCL and VCL.NET Component Designers DevCon 2005 -- Course No: 3146."— Presentation transcript:

1 Ray Konopka Developing Custom VCL and VCL.NET Component Designers DevCon 2005 -- Course No: 3146

2 2 Agenda The Delphi design-time environment Property Editors TAlign property editor Integer property editor Component Editors TButton component editor TListBox component editor TRadioGroup component editor The Delphi design-time environment Property Editors TAlign property editor Integer property editor Component Editors TButton component editor TListBox component editor TRadioGroup component editor

3 3 The Design-Time Environment Object Inspector uses property editors to Display individual property values Edit individual property values Form Designer uses component editors to Edit component as a whole Add items to context menu Respond to double clicks Object Inspector uses property editors to Display individual property values Edit individual property values Form Designer uses component editors to Edit component as a whole Add items to context menu Respond to double clicks

4 4 Important Points Design editors work seamlessly within the design environment Properties and components are not aware of the editors Delphi uses It is possible to replace an existing editor. Design editors work seamlessly within the design environment Properties and components are not aware of the editors Delphi uses It is possible to replace an existing editor.

5 5 Property Editors Why create custom property editors? Provide an alternate way of editing a property Supply a drop-down list with predefined values Display a custom dialog to modify the property visually Support a non-standard custom property Why create custom property editors? Provide an alternate way of editing a property Supply a drop-down list with predefined values Display a custom dialog to modify the property visually Support a non-standard custom property

6 6 Property Editor Tasks Convert property value Native Format  string Define how the property can be edited Inline - within the Object Inspector Dialog - using a separate dialog box. Convert property value Native Format  string Define how the property can be edited Inline - within the Object Inspector Dialog - using a separate dialog box.

7 7 Standard Property Editors All property editors descend from TPropertyEditor Defined in the following units DesignIntf DesignEditors VclEditors DesignMenus For VCL.NET, must prefix namespace Borland.Vcl.Design.DesignIntf Borland.Vcl.Design.DesignEditors Borland.Vcl.Design.VCLEditors Borland.Vcl.Design.DesignMenus. All property editors descend from TPropertyEditor Defined in the following units DesignIntf DesignEditors VclEditors DesignMenus For VCL.NET, must prefix namespace Borland.Vcl.Design.DesignIntf Borland.Vcl.Design.DesignEditors Borland.Vcl.Design.VCLEditors Borland.Vcl.Design.DesignMenus.

8 8 TIntegerProperty TCharProperty TCursorProperty TPropertyEditor TEnumProperty TOrdinalProperty TColorProperty TClassProperty TFloatProperty TSetElementProperty TStringProperty TStringListProperty TCaptionProperty TFontProperty TMethodProperty TComponentProperty TSetProperty TFontNameProperty

9 9 Creating a New Property Editor Create a descendant of TPropertyEditor Usually descend from standard editor Ensure Value property works properly Not a concern if inheriting from standard editor Define the editing capabilities of the editor Implement appropriate interface methods Register the property editor. Create a descendant of TPropertyEditor Usually descend from standard editor Ensure Value property works properly Not a concern if inheriting from standard editor Define the editing capabilities of the editor Implement appropriate interface methods Register the property editor.

10 10 Implementing GetValue Use the following methods to get the value stored in the property GetFloatValue, GetInt64Value, GetOrdValue, GetStrValue, GetMethodValue, GetVarValue For object references GetOrdValue in VCL GetObjValue in VCL.NET Use the following methods to get the value stored in the property GetFloatValue, GetInt64Value, GetOrdValue, GetStrValue, GetMethodValue, GetVarValue For object references GetOrdValue in VCL GetObjValue in VCL.NET function TIntegerProperty.GetValue: string; begin Result := IntToStr( GetOrdValue ); end; function TIntegerProperty.GetValue: string; begin Result := IntToStr( GetOrdValue ); end;

11 11 Implementing SetValue Use the following methods to set the property value SetFloatValue, SetInt64Value, SetOrdValue, SetStrValue, SetMethodValue, SetVarValue For object references SetOrdValue in VCL SetObjValue in VCL.NET Use the following methods to set the property value SetFloatValue, SetInt64Value, SetOrdValue, SetStrValue, SetMethodValue, SetVarValue For object references SetOrdValue in VCL SetObjValue in VCL.NET function TFloatProperty.SetValue( const Value: string ); begin SetFloatValue( StrToFloat( Value ) ); end; function TFloatProperty.SetValue( const Value: string ); begin SetFloatValue( StrToFloat( Value ) ); end;

12 12 Overriding GetAttributes Determines how editor appears in the Object Inspector Returns a set of attributes Common attributes paValueList paSortList paDialog paMultiSelect paAutoUpdate Determines how editor appears in the Object Inspector Returns a set of attributes Common attributes paValueList paSortList paDialog paMultiSelect paAutoUpdate

13 13 The GetValues Method Override when paValueList is specified Specify values to appear in drop down list Proc points to Add method of temp string list Override when paValueList is specified Specify values to appear in drop down list Proc points to Add method of temp string list procedure TFontNameProperty.GetValues( Proc: TGetStrProc ); var I: Integer; begin for I := 0 to Screen.Fonts.Count - 1 do Proc( Screen.Fonts[ I ] ); end; procedure TFontNameProperty.GetValues( Proc: TGetStrProc ); var I: Integer; begin for I := 0 to Screen.Fonts.Count - 1 do Proc( Screen.Fonts[ I ] ); end;

14 14 Owner-Draw Drop-Down Lists Customize the appearance of items in list Implement the following interfaces ICustomPropertyDrawing  ListMeasureHeight  ListMeasureWidth  ListDrawValue ICustomPropertyListDrawing  PropDrawName  PropDrawValue Customize the appearance of items in list Implement the following interfaces ICustomPropertyDrawing  ListMeasureHeight  ListMeasureWidth  ListDrawValue ICustomPropertyListDrawing  PropDrawName  PropDrawValue

15 15 The Edit Method Override Edit to perform action when ellipsis button is pressed or entry is double-clicked Typically used to display a custom dialog TFontProperty Not necessary to display a dialog box TMethodProperty generates an empty even handler Override Edit to perform action when ellipsis button is pressed or entry is double-clicked Typically used to display a custom dialog TFontProperty Not necessary to display a dialog box TMethodProperty generates an empty even handler

16 16 Registering a Property Editor Define a Register procedure Registration unit recommended Call RegisterPropertyEditor Parameters determine scope of editor Define a Register procedure Registration unit recommended Call RegisterPropertyEditor Parameters determine scope of editor // Edit all TStrings properties with TStringListProperty RegisterPropertyEditor( TypeInfo( TStrings ), nil, '', TStringListProperty ); // But edit the TQuery.SQL property with TRkSQLProperty RegisterPropertyEditor( TypeInfo( TStrings ), TQuery, 'SQL', TRkSQLProperty ); // Edit all TStrings properties with TStringListProperty RegisterPropertyEditor( TypeInfo( TStrings ), nil, '', TStringListProperty ); // But edit the TQuery.SQL property with TRkSQLProperty RegisterPropertyEditor( TypeInfo( TStrings ), TQuery, 'SQL', TRkSQLProperty );

17 17 Examples TRkAlignProperty Inline editor with owner draw drop-down list TRkIntegerProperty Dialog-based property editor TRkAlignProperty Inline editor with owner draw drop-down list TRkIntegerProperty Dialog-based property editor

18 18 Component Editors Why create custom component editors? Add menu items to context menu displayed by Form Designer Change double-click action Easier to create than property editors No need to worry about string representation. Why create custom component editors? Add menu items to context menu displayed by Form Designer Change double-click action Easier to create than property editors No need to worry about string representation.

19 19 Creating a Component Editor Derive a new class from TComponentEditor TDefaultEditor Define the editing capabilities of the editor Override appropriate methods Register the component editor. Derive a new class from TComponentEditor TDefaultEditor Define the editing capabilities of the editor Override appropriate methods Register the component editor.

20 20 TDefaultEditor Overrides the Edit method When component is double-clicked, Edit searches for the following events: OnCreate OnChange OnClick First defined event Generates (or navigates to) event handler Overrides the Edit method When component is double-clicked, Edit searches for the following events: OnCreate OnChange OnClick First defined event Generates (or navigates to) event handler

21 21 Context Menu Methods Override GetVerbCount Return number of menu items to add Override GetVerb Return string to display for corresponding menu item Override ExecuteVerb Implement functionality of new menu items Override GetVerbCount Return number of menu items to add Override GetVerb Return string to display for corresponding menu item Override ExecuteVerb Implement functionality of new menu items

22 22 The PrepareItem Method Provides access to menu item object for each menu item Actually an IMenuItem interface Allows menu items to be customized Enabled/Disabled Checked/Unchecked Create Sub-Menus Unfortunately, you cannot specify an ImageIndex or Glyph to be used for the menu Provides access to menu item object for each menu item Actually an IMenuItem interface Allows menu items to be customized Enabled/Disabled Checked/Unchecked Create Sub-Menus Unfortunately, you cannot specify an ImageIndex or Glyph to be used for the menu

23 23 The Edit Method Override to respond to double click The Edit method of TComponentEditor invokes ExecuteVerb( 0 ) if applicable Override to respond to double click The Edit method of TComponentEditor invokes ExecuteVerb( 0 ) if applicable

24 24 Registering a Component Editor Use the RegisterComponentEditor procedure Most recently registered editor will be used for editing the component This allows you to replace an existing editor Use the RegisterComponentEditor procedure Most recently registered editor will be used for editing the component This allows you to replace an existing editor RegisterComponentEditor( TRadioGroup, TRkRadioGroupEditor ); RegisterComponentEditor( TRadioGroup, TRkRadioGroupEditor );

25 25 Example TRkButtonEditor Add menu items Displays a custom dialog TRkListBoxEditor Add menu items and sub-menu items to context menu EditPropertyByName in RkDesignEditors unit TRkRadioGroupEditor Displays a custom dialog Dynamic cascading menus Registration Units TRkButtonEditor Add menu items Displays a custom dialog TRkListBoxEditor Add menu items and sub-menu items to context menu EditPropertyByName in RkDesignEditors unit TRkRadioGroupEditor Displays a custom dialog Dynamic cascading menus Registration Units

26 26 The Finish Line Contact Information Evaluation Forms Questions & Answers Contact Information Evaluation Forms Questions & Answers Ray Konopka rkonopka@raize.com http://www.raize.com Ray Konopka rkonopka@raize.com http://www.raize.com


Download ppt "Ray Konopka Developing Custom VCL and VCL.NET Component Designers DevCon 2005 -- Course No: 3146."

Similar presentations


Ads by Google