t e m p o r a l 
 d o o r w a y 

Writing A Component Editor

 

Sometimes, you can create a component whose properties are so complex that the interface provided by the object inspector is just not sufficient. In those cases, you can add a component editor to your class, whose job it is to provide the desired user interface.

A component editor, like a property editor, can use any of the features of the C++Builder environment, especially including forms. Thus, you can offer a window with a complex set of controls as the interface to provide design time settings for your component properties.

The declaration shown goes at the base of the a component's header file. Note that the override of Edit() (which is what is normally invoked by the IDE when the component is double-clicked) must call Designer->Modified() to notify the IDE that the component has changed.

In the example below, you must implement EditComponent as a member of SampleComponent. It can, of course, use a comventional C++ Builder form. Also note the cast of the internal variable "Component" to the actual type of your component. Again, your component class must contain the implementation of EditComponent.

class SampleComponentEditor: public TComponentEditor
{
   public:

      __fastcall SampleComponentEditor(Classes::TComponent* AComponent, TFormDesigner* ADesigner):TComponentEditor(AComponent,ADesigner){};

      void __fastcall Edit(void){((SampleComponent *) Component)->EditComponent; Designer->Modified();};
};

The following is needed to register the component editor. It goes right after RegisterComponent in the Register() function of the component .cpp file, since the component editor in this example is in the component files. If the component editor were in its own .h and .cpp files, then this would appear in that .cpp file.

RegisterComponentEditor(__classid(SampleComponent),__classid(SampleComponentEditor));

So there you go - the basics of a component editor. It isn't so hard to interface to one, and with the facilities of C++Builder for form design and interaction development, you will find it easy to set up an editor for the most complex component.

Copyright © 2004 by Mark Cashman (unless otherwise indicated), All Rights Reserved