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

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

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

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

Ray KonopkaRay Konopka

Developing Custom VCL and VCL.NET Component

Designers

Developing Custom VCL and VCL.NET Component

DesignersDevCon 2005 -- Course No: 3146DevCon 2005 -- Course No: 3146

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

2

AgendaAgenda

The Delphi design-time environment

Property EditorsTAlign property editorInteger property editor

Component EditorsTButton component editorTListBox component editorTRadioGroup component editor

The Delphi design-time environment

Property EditorsTAlign property editorInteger property editor

Component EditorsTButton component editorTListBox component editorTRadioGroup component editor

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

3

The Design-Time Environment

The Design-Time Environment

Object Inspector uses property editors toDisplay individual property valuesEdit individual property values

Form Designer uses component editors toEdit component as a wholeAdd items to context menuRespond to double clicks

Object Inspector uses property editors toDisplay individual property valuesEdit individual property values

Form Designer uses component editors toEdit component as a wholeAdd items to context menuRespond to double clicks

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

4

Important PointsImportant 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.

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

5

Property EditorsProperty Editors

Why create custom property editors?

Provide an alternate way of editing a propertySupply a drop-down list with predefined valuesDisplay 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 propertySupply a drop-down list with predefined valuesDisplay a custom dialog to modify the property

visually

Support a non-standard custom property

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

6

Property Editor TasksProperty Editor Tasks

Convert property valueNative Format string

Define how the property can be editedInline - within the Object InspectorDialog - using a separate dialog box.

Convert property valueNative Format string

Define how the property can be editedInline - within the Object InspectorDialog - using a separate dialog box.

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

7

Standard Property EditorsStandard Property Editors

All property editors descend from TPropertyEditor

Defined in the following unitsDesignIntfDesignEditorsVclEditorsDesignMenus

For VCL.NET, must prefix namespaceBorland.Vcl.Design.DesignIntfBorland.Vcl.Design.DesignEditorsBorland.Vcl.Design.VCLEditorsBorland.Vcl.Design.DesignMenus.

All property editors descend from TPropertyEditor

Defined in the following unitsDesignIntfDesignEditorsVclEditorsDesignMenus

For VCL.NET, must prefix namespaceBorland.Vcl.Design.DesignIntfBorland.Vcl.Design.DesignEditorsBorland.Vcl.Design.VCLEditorsBorland.Vcl.Design.DesignMenus.

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

8

TIntegerProperty

TCharProperty

TCursorProperty

TPropertyEditor

TEnumProperty

TOrdinalProperty

TColorProperty

TClassProperty

TFloatProperty

TSetElementProperty

TStringProperty

TStringListProperty

TCaptionProperty

TFontProperty

TMethodProperty

TComponentProperty

TSetProperty

TFontNameProperty

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

9

Creating a New Property Editor

Creating a New Property Editor

Create a descendant of TPropertyEditorUsually descend from standard editor

Ensure Value property works properlyNot a concern if inheriting from standard editor

Define the editing capabilities of the editorImplement appropriate interface methods

Register the property editor.

Create a descendant of TPropertyEditorUsually descend from standard editor

Ensure Value property works properlyNot a concern if inheriting from standard editor

Define the editing capabilities of the editorImplement appropriate interface methods

Register the property editor.

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

10

Implementing GetValueImplementing GetValue

Use the following methods to get the value stored in the property

GetFloatValue, GetInt64Value, GetOrdValue, GetStrValue, GetMethodValue, GetVarValue

For object referencesGetOrdValue in VCLGetObjValue in VCL.NET

Use the following methods to get the value stored in the property

GetFloatValue, GetInt64Value, GetOrdValue, GetStrValue, GetMethodValue, GetVarValue

For object referencesGetOrdValue in VCLGetObjValue in VCL.NET

function TIntegerProperty.GetValue: string;begin Result := IntToStr( GetOrdValue );end;

function TIntegerProperty.GetValue: string;begin Result := IntToStr( GetOrdValue );end;

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

11

Implementing SetValueImplementing SetValue

Use the following methods to set the property value

SetFloatValue, SetInt64Value, SetOrdValue, SetStrValue, SetMethodValue, SetVarValue

For object referencesSetOrdValue in VCLSetObjValue in VCL.NET

Use the following methods to set the property value

SetFloatValue, SetInt64Value, SetOrdValue, SetStrValue, SetMethodValue, SetVarValue

For object referencesSetOrdValue in VCLSetObjValue in VCL.NETfunction TFloatProperty.SetValue( const Value: string );

begin SetFloatValue( StrToFloat( Value ) );end;

function TFloatProperty.SetValue( const Value: string );begin SetFloatValue( StrToFloat( Value ) );end;

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

12

Overriding GetAttributesOverriding GetAttributes

Determines how editor appears in the Object Inspector

Returns a set of attributes

Common attributespaValueListpaSortListpaDialogpaMultiSelectpaAutoUpdate

Determines how editor appears in the Object Inspector

Returns a set of attributes

Common attributespaValueListpaSortListpaDialogpaMultiSelectpaAutoUpdate

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

13

The GetValues MethodThe 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;

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

14

Owner-Draw Drop-Down Lists

Owner-Draw Drop-Down Lists

Customize the appearance of items in list

Implement the following interfacesICustomPropertyDrawing

ListMeasureHeight ListMeasureWidth ListDrawValue

ICustomPropertyListDrawing PropDrawName PropDrawValue

Customize the appearance of items in list

Implement the following interfacesICustomPropertyDrawing

ListMeasureHeight ListMeasureWidth ListDrawValue

ICustomPropertyListDrawing PropDrawName PropDrawValue

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

15

The Edit MethodThe Edit Method

Override Edit to perform action when ellipsis button is pressed or entry is double-clicked

Typically used to display a custom dialogTFontProperty

Not necessary to display a dialog boxTMethodProperty 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 dialogTFontProperty

Not necessary to display a dialog boxTMethodProperty generates an empty even

handler

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

16

Registering a Property Editor

Registering a Property Editor

Define a Register procedureRegistration unit recommended

Call RegisterPropertyEditor

Parameters determine scope of editor

Define a Register procedureRegistration unit recommended

Call RegisterPropertyEditor

Parameters determine scope of editor

// Edit all TStrings properties with TStringListPropertyRegisterPropertyEditor( TypeInfo( TStrings ), nil, '', TStringListProperty );

// But edit the TQuery.SQL property with TRkSQLPropertyRegisterPropertyEditor( TypeInfo( TStrings ), TQuery, 'SQL', TRkSQLProperty );

// Edit all TStrings properties with TStringListPropertyRegisterPropertyEditor( TypeInfo( TStrings ), nil, '', TStringListProperty );

// But edit the TQuery.SQL property with TRkSQLPropertyRegisterPropertyEditor( TypeInfo( TStrings ), TQuery, 'SQL', TRkSQLProperty );

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

17

ExamplesExamples

TRkAlignPropertyInline editor with owner draw drop-down list

TRkIntegerPropertyDialog-based property editor

TRkAlignPropertyInline editor with owner draw drop-down list

TRkIntegerPropertyDialog-based property editor

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

18

Component EditorsComponent Editors

Why create custom component editors?Add menu items to context menu displayed by

Form DesignerChange double-click action

Easier to create than property editorsNo need to worry about string representation.

Why create custom component editors?Add menu items to context menu displayed by

Form DesignerChange double-click action

Easier to create than property editorsNo need to worry about string representation.

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

19

Creating a Component Editor

Creating a Component Editor

Derive a new class from TComponentEditorTDefaultEditor

Define the editing capabilities of the editorOverride appropriate methods

Register the component editor.

Derive a new class from TComponentEditorTDefaultEditor

Define the editing capabilities of the editorOverride appropriate methods

Register the component editor.

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

20

TDefaultEditorTDefaultEditor

Overrides the Edit method

When component is double-clicked, Edit searches for the following events:OnCreateOnChangeOnClickFirst defined event

Generates (or navigates to) event handler

Overrides the Edit method

When component is double-clicked, Edit searches for the following events:OnCreateOnChangeOnClickFirst defined event

Generates (or navigates to) event handler

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

21

Context Menu MethodsContext Menu Methods

Override GetVerbCountReturn number of menu items to add

Override GetVerbReturn string to display for corresponding menu

item

Override ExecuteVerbImplement functionality of new menu items

Override GetVerbCountReturn number of menu items to add

Override GetVerbReturn string to display for corresponding menu

item

Override ExecuteVerbImplement functionality of new menu items

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

22

The PrepareItem MethodThe PrepareItem Method

Provides access to menu item object for each menu itemActually an IMenuItem interface

Allows menu items to be customizedEnabled/DisabledChecked/UncheckedCreate 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 itemActually an IMenuItem interface

Allows menu items to be customizedEnabled/DisabledChecked/UncheckedCreate Sub-Menus

Unfortunately, you cannot specify an ImageIndex or Glyph to be used for the menu

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

23

The Edit MethodThe 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

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

24

Registering a Component Editor

Registering a Component Editor

Use the RegisterComponentEditor procedure

Most recently registered editor will be used for editing the componentThis allows you to replace an existing editor

Use the RegisterComponentEditor procedure

Most recently registered editor will be used for editing the componentThis allows you to replace an existing editor

RegisterComponentEditor( TRadioGroup, TRkRadioGroupEditor );RegisterComponentEditor( TRadioGroup, TRkRadioGroupEditor );

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

25

ExampleExample

TRkButtonEditorAdd menu itemsDisplays a custom dialog

TRkListBoxEditorAdd menu items and sub-menu items to context

menuEditPropertyByName in RkDesignEditors unit

TRkRadioGroupEditorDisplays a custom dialogDynamic cascading menus

Registration Units

TRkButtonEditorAdd menu itemsDisplays a custom dialog

TRkListBoxEditorAdd menu items and sub-menu items to context

menuEditPropertyByName in RkDesignEditors unit

TRkRadioGroupEditorDisplays a custom dialogDynamic cascading menus

Registration Units

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

26

The Finish LineThe Finish Line

Contact Information

Evaluation Forms

Questions & Answers

Contact Information

Evaluation Forms

Questions & Answers

Ray [email protected]://www.raize.com

Ray [email protected]://www.raize.com