1 / 26

Developing Custom VCL and VCL.NET Component Designers

Developing Custom VCL and VCL.NET Component Designers. DevCon 2005 -- Course No: 3146. Agenda. The Delphi design-time environment Property Editors TAlign property editor Integer property editor Component Editors TButton component editor TListBox component editor

gaetan
Download Presentation

Developing Custom VCL and VCL.NET Component Designers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  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

  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

  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.

  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

  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.

  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.

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

  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.

  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 function TIntegerProperty.GetValue: string; begin Result := IntToStr( GetOrdValue ); end;

  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 function TFloatProperty.SetValue( const Value: string ); begin SetFloatValue( StrToFloat( Value ) ); end;

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

  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 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 • Customize the appearance of items in list • Implement the following interfaces • ICustomPropertyDrawing • ListMeasureHeight • ListMeasureWidth • ListDrawValue • ICustomPropertyListDrawing • PropDrawName • PropDrawValue

  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

  16. Registering a Property 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 );

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

  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.

  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.

  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

  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

  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

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

  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 RegisterComponentEditor( TRadioGroup, TRkRadioGroupEditor );

  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

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

More Related