Chapter 5. Creating Property and Component Editors

   

IN THIS CHAPTER

  • Creating Custom Property Editors

  • Properties and Exceptions

  • Registering Custom Property Editors

  • Using Images in Property Editors

  • Creating Custom Component Editors

  • Registering Component Editors

Components are the building blocks of C++Builder. They are the essential elements of every C++Builder program. Developers spend much of their time working with components, learning about their features, and trying to make the best use of the facilities that they offer. To that end, improving the design-time interface of a component is one of the single most powerful ways to improve a component's usefulness . Developers often spend great effort on improving their application's user interface for their customers. Component writers should also consider the interface that they present to their customers ”the developers.

This chapter covers the techniques required to successfully implement property editors and component editors. Some of the biggest changes to C++Builder's IDE have been to allow improved property and component interfaces at design time to help improve the productivity of developers. All the new features added in C++Builder are covered in depth, and definitive guidelines are presented as to their proper use.

All the code of the property editors and component editors discussed in this chapter is contained on the accompanying CD-ROM. By examining the source to these editors, it should be possible to develop a good understanding of the issues involved in creating custom editors for components. The code shown in the listings throughout the chapter is contained in two packages: the EnhancedEditors package ( EnhancedEditors.bpk , a design time “only package), and the NewAdditionalComponents design time and runtime pack-ages. The design-time package, called NewAdditionalComponentsDTP.bpk , contains property and component editor code as well as registration code. The runtime package, called NewAdditionalComponentsRTP.bpk , contains code for components.

It would probably be helpful to install these packages into your installation of C++Builder before reading this chapter. That way you can see the effect that the property and component editors have while you are reading the chapter. Before you install either package, first copy the folder called Chapter5Packages to your hard drive. It contains the files you require. Feel free to give the folder a more imaginative name . Then, copy both files in the System folder to a folder on the system path , for example, Windows\System on Windows 9x machines or WINNT\System32 on Windows NT and Windows 2000 machines. These files are runtime packages required by the two design-time packages you will install shortly. Both of those design-time packages require the TNonVCLTypeInfoPackage.bpl runtime-only file, and the NewAdditionalComponentsDTP.bpl design time “only package also requires the NewAdditionalComponentsRTP.bpl runtime-only package.

There are several additional directories that should also be copied to some location where you keep your development source code files:

  • NonVCLTypeInfoPackage ” provides runtime type information for types not based on Tobject.

  • NewAdditionalComponents (Contains NewAddtionalComponentsRTP and NewAdditionalComponentsDTP for the runtime and design-time packages respectively ” provides various components to use the property and component editors.

  • EnhancedEditors ” provides special component and property editors for use with the "new additional components".

Each of these contains source code and projects needed to demonstrate the content of this chapter.

To install the EnhancedEditors package, run C++Builder and click Install Packages in the Component menu. Click the Add button in the Design packages group and browse to where you have copied the EnhancedEditors\BPL directory and select the EnhancedEditors.bpl file. When you click Open, the Add Design Package dialog will close and the package will appear in the Design packages list as Enhanced Property and Component Editors. Click OK to finish. Table 5.1 lists the property and component editors contained in the EnhancedEditors package and indicates whether they are registered (in other words, installed) with the IDE when the package is installed.

Table 5.1. Property and Component Editors Registered by the EnhancedEditors Package

Editors

Registered

TShapeTypePropertyEditor

Yes

TImageListPropertyEditor

Yes

TImageIndexProperty

No ”An Abstract Base Class

TPersistentDerivedImageIndexProperty

Yes

TComponentDerivedImageIndexProperty

Yes

TMenuItemImageIndexProperty

Yes

TTabSheetImageIndexProperty

Not required

TToolButtonImageIndexProperty

Yes

TCoolBandImageIndexProperty

Not required

TListColumnImageIndexProperty

Yes

TCustomActionImageIndexProperty

Not required

THeaderSectionImageIndexProperty

Not required

TDisplayCursorProperty

Yes

TDisplayFontNameProperty

Yes

TUnsignedProperty

Yes

TCharPropertyEditor

Yes

TSignedCharProperty

Yes

TUnsignedCharProperty

Yes

TImageComponentEditor

Yes

The method for installing the NewAdditionalComponents package is the same as for the EnhancedEditors package. Click Install Packages on the Component menu. Click the Add button in the Design packages group and browse into the NewAdditional Components\NewAdditionalComponentsDTP\BPL directory for the NewAdditional ComponentsDTP.bpl file. When you click Open, the Add Design Package dialog will close, and the package will appear in the Design packages list as New Components for the Additional Palette Page. Click OK to finish. The following components are registered with the IDE by this package:

  • TEnhancedImage

  • TFilterEdit

The TImageIndexPropertyEditor property editor is also registered by this package. Additionally, the TNonVCLTypeInfoPackage runtime-only package ( TNonVCLTypeInfoPackage.bpk ) is included. This contains code referred to in Listings 5.7 and 5.8 in the section "Obtaining a TTypeInfo* (PTypeInfo) from an Existing Property and Class for a Non-VCL Type," later in this chapter. Both the EnhancedEditors.bpk and the NewAdditionalComponentsDTP.bpk package require this package for their regis-tration code. Therefore, if you want to recompile either package, the header files ( *.h ) and import file ( .bpi ) of this package must be found by the IDE when it is compiling and linking the packages.


   
Top


C++ Builder Developers Guide
C++Builder 5 Developers Guide
ISBN: 0672319721
EAN: 2147483647
Year: 2002
Pages: 253

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net