|
|
 |
 |
|
Join the Discussion
|
"Post your questions, concerns, views and comments to this article..."
Discuss!
|
|
 |
 |
|
|
 |
 |
 |
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
|