Ray Konopka Developing Custom VCL and VCL.NET Component Designers DevCon 2005 -- Course No: 3146.
-
Upload
vanessa-shields -
Category
Documents
-
view
226 -
download
0
Transcript of 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
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
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
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.
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
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.
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.
8
TIntegerProperty
TCharProperty
TCursorProperty
TPropertyEditor
TEnumProperty
TOrdinalProperty
TColorProperty
TClassProperty
TFloatProperty
TSetElementProperty
TStringProperty
TStringListProperty
TCaptionProperty
TFontProperty
TMethodProperty
TComponentProperty
TSetProperty
TFontNameProperty
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.
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;
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;
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
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;
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
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
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 );
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
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.
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.
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
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
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
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
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 );
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
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