1. Technology

Your suggestion is on its way!

An email with a link to:

http://delphi.about.com/library/bluc/text/uc092501a.htm

was emailed to:

Thanks for sharing About.com with others!

RTL reference|Glossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link To

Creating Custom Delphi Components, Part III
Page 1: Custom Editors; Coding standards
More of this Feature
Page 2: Component Editors
Page 3: Property Editors
Page 4: Dialog Editors

Download Demo Projects
Join the Discussion
"Post your questions, concerns, views and comments to this article..."
Discuss!
Related Resources
Custom VCL development
Third party VCL
VCL using

Article submitted by: Peter Morris
"This article originally appeared in Delphi Developer. Copyright Pinnacle Publishing, Inc. All rights reserved."

This article is the final part of a three part article on components. Part one covered the basic creating of components, part two covered how to write advanced properties, how to write custom streaming for those properties, and sub-properties. This final part will cover property / component editors, how to write dedicated editors for your component / property, and how to write "hidden" components.

Custom Component Editors
As soon as we start to write advanced property types for our components, life becomes a little more complicated. Although the object inspector built into Delphi is able to recognise most property types, it is impossible for it to be able to deal with every possible custom type we may write into our components. Sometimes the object inspector is able to deal with our custom types, but editing such a complex arrangement of properties in the object inspector is simply not intuitive enough. It is at this point we may be required to write property / component editors. Delphi has many predefined editors already, these editors are in the DsgnIntf.pas file in the $(Delphi)\Source\ToolsAPI directory. You will need to list this unit in the uses clause of any component editor / property editor you may write, it is also a good idea to keep this file open for reference when writing your own editors.

Coding standards
To start off with I will cover some coding standards that are used when writing component or property editors. There are only a few, but it would be a good idea to keep to these standards when writing your own editors as it makes it easier for other people to understand your work.

  • When creating a property editor, end the name of your editor with the word "Property"; for example TAngleProperty
  • When creating a component editor, end the name of your editor with the word "Editor"; for example TPieChartEditor
  • When writing editors, always write the editor in a separate unit to your actual component. It is good to separate the design time and runtime code and, apart from this, it makes your resulting EXE size smaller (on some versions of Delphi your component may stop applications from compiling if you do not separate them).
  • Name your editor unit with the same name as your component unit, but append the word "reg" at the end; for example, a component with the unit name "MyComponent.pas" would result in the editor filename being "MyComponentreg.pas"
  • Finally, when writing a component editor / property editor for your component, move your RegisterComponents statement out of your component's unit, and into your component editor's unit. This way your component will not be registered without the editor also being registered.

Next page > Component Editors > Page 1, 2, 3, 4

All graphics (if any) in this feature created by Peter Morris.

More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time.
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: Lookup! - DB/15.
Chapter fifteen of the free Delphi Database Course for beginners. See how to use lookup fields in Delphi to achieve faster, better and safer data editing. Also, find how to create a new field for a dataset and discuss some of the key lookup properties. Plus, take a look at how to place a combo box inside a DBGrid.
Stay informed with all new and interesting things about Delphi (for free).
Subscribe to the Newsletter
Name
Email

Got some code to share? Got a question? Need some help?

©2014 About.com. All rights reserved.