Copyright: Visual Help Copyright® 1993 Firas Bushnaq


Contents

How to Build a Component

What Component Builder is and what it is not

Product Support

How to Register

Frequently Asked Questions

Miscellaneous

About this Help file


How to Build a Component

If you write components for Delphi, you need Component Builder.  Component Builder speeds through the task of defining properties, methods and event handlers and creates an output source file that can be compiled and installed into the component library.  All you'll need to do is add the specific code to the methods and functions created by Component Builder and your component's done.

The entire process is accomplished in seven easy steps:

Step 1:

Define the component's class, ancestor and select the palette page

Step 2:

Define the component's properties

Step 3:

Define methods

Step 4:

Define event handlers

Step 5:

Build output

Step 6:

Edit and add code if necessary

Step 7:

Save your work

See Also:

Installing New Components


Define the Component

The first step is creating your component is to define the class, ancestor and palette page.  By default, the unit name is 'unit1.pas'.  You can change this if you want, but be sure to include the path name as well.

1	Define the class name you want to use for your component.  For example: TRotateLabel

2	Select the ancestor. For Example: TComponent

3	Select the Palette page for example 'Samples'


Defining Properties

The property name and data type are required.  All other property attributes are optional.  Defining a property is easy let's use an example to illustrate the process.  Suppose you want to construct a component that reads a text file and counts the number of lines in the file.  To do this we'll need a property to hold the line count, let's call it Count.  Also, we want this property to be read only and run time only since it has no value in design mode.  The following process is all that's necessary to define this property:

1	Type in Count for the property name.

2	Select the property data type as longint since there could be more than 32767 lines in the file.

3	Check the check boxes for run time only and read only.

4	Select Direct Access for read access.  You'll note that write access has been disabled since we checked read only.

5	Click the Add button to add this property to the list of defined properties.

Note:

If you need to eliminate a previously defined property, select it from the list of Defined Properties and click the Remove button.

See Also:

Property Data Types

Property Access Methods

Runtime Only Properties

Read Only Properties

Write Only Properties

Protected Properties

Default Value

Removing Properties


Property Data Types

Select a data type from the list or enter a type that is not in the list.  A property can have a type that is not one of the simple types in the list, for example TStringList.


Property Access Methods

Properties can be accessed at run time by either of two methods:

Direct Access:

The property's value is either read or written by accessing the underlying variable directly.

Access Methods:

A function or procedure is used to access or set the value of the underlying variable for a property.

The Component Writer's Guide contains a detailed explanation of property access on pages 35-36.  The type of access will be determined by what the property is designed to do.


Runtime Only Properties

A property that is defined as runtime only will not appear in the Object Inspector when Delphi is in design mode.  The property may be accessed only at runtime.


Read Only Properties

A Read Only Property is exactly that 'Read Only'.  The property value cannot be changed and will not be visible in the Object Inspector while in design mode.


Write Only Properties

Write Only properties are rare.  By setting this attribute, the property's value can only be written, not read.


Protected Properties

Select the Protected attribute to make a property protected.  Refer to page 33 of the Component Writer's Guide.


Default Value

Enter the default property value if you need one.  Be sure that the value you enter is compatible with the data type you choose for the property.  For example, don't enter 'abc' with a data type of integer.


REMOVING PROPERTIES METHODS AND EVENTS
Removing Properties, Methods and Events

To remove a property, method or event handler that has been previously defined, select it from the list and click the remove button.  If you have previously done a build, you'll want to rebuild the output by clicking the Build button again.


Defining Methods

To define a component method type in a name for the method, select the type (either function or procedure) give it the paramater list and if it is a function, select the type of data it returns.  Note that the paramater list should not include the parentheses, for example just   ' i : integer' is all that's needed (without the quotes of course).  The method declaration and code skeleton are built for you but of course you'll have to add the 'real' code the makes the method perform it's assigned task.  I'd love to be able to do that for you too, but I can't read your mind at run time.


Defining Event Handlers

To define an event handler, give it a name, select the type (probably TNotifyEvent) and give it a paramater list.  Don't include the parentheses in the paramater list, just 's : string' will do.  If your wondering what an event handler is refer to the Component Writer's Guide.  In fact if your wondering that at this point, you probably need to read the entire Guide before proceeding.


Building the Output

Click the Build button or select Build Source Output from the menu.  The actual output is displayed on the Tab Page captioned 'Output'.  You can then add your code for methods, event handlers, etc. before saving the output to a file.


Adding Code

For your component to do anything really useful, you'll need to add the code to the method and event handler skeletons.  You can do that right on the output page before saving the finished source.


Saving Your Work

Before exiting Component Builder, you'll want to save your work.  Click the save button or select 'Build|Save .pas file' from the menu.  If you don't have a registered version of this product, you won't be able to save to a file.
The actual output file is named according to the unit name on the Class page.  You'll also be asked if you want to save the component specifications before exiting.  You should do so if you will need to retrieve the property, method and event definitions for later use with Component builder.


Installing New Components

There are two ways to install your newly created component.

1	From the Delphi menu select Options|Install Components

2	From the Component Builder menu select Build|Install New Component.  Component Builder does the work for you.


WHAT IT IS
What it is ?

Component Builder will create all the necessary code for a component source file including underlying variable declarations, method and event handler declarations and property declarations.  It will build the code skeletons for methods, etc. as well as the declarations.  It saves you a LOT of typing and eliminates a lot of errors as well, but here's .....

What it ain't !

Component Builder will not read your mind and build you a tailor made component with all the functionality you envision.  You have to add the 'real' code to provide the functionality you want your component to have.


Product Support

You can contact me through Compuserve 76350,3301 for product support. I'll be happy to answer any questions.  If you find a bug, let me know I'll fix it.  If you have any suggestions for improvement, let me know.  If you're not a compuserve member leave me e-mail at 76350.3301@compuserve.com.

You can contact me via postal mail or voice at:

John C. Taylor
3475 Holcomb Br Rd
Suite 202
Norcross, GA   30092

Phone (770)-449-6284

If you call my voice you may well get my voice mail, if so, leave me a message.  I really prefer to be contacted via e-mail.


How to Register

You can register this product by sending me 20 bucks (US).  This ain't much and I'll have to go to the trouble to send you the registered version.
You can also register via Compuserve SWREG # 8257.  If you're unfamiliar with registering shareware through Compuserve, just GO SWREG and follow the instructions.

Where to send money:

John C. Taylor
3475 Holcomb Br Rd
Suite 202
Norcross, Ga   30092


Frequently Asked Questions

Q.  How do I install my newly created component ?

A.  From the Delphi menu choose 'Options|Install Components'.  Select the newly created component.  It will be the file name and path you entered in the unit name box on the Class page.  You can also select 'Install|Install new component' from CB's menu. If Delphi is not running, this item is disabled.

Q.  I defined my property and did a Build but I didn't see it on the output page.  What went wrong ?

A.  Don't forget to click the Add button to add the property to the list of Defined Properties.

Q.  How can I change a previously defined property ?

A.  Select and remove it from the list of defined properties.  Then
redefine it and add it back to the list.

Q.  How can I save my work before I'm ready to build the final output ?

A.  Select 'File|Save *.spc file' from the menu.


Other Topics

Adding Component Builder to Delphi's menu:

Select 'Install|Add to tools menu' from CB's menu to add Component Builder to the Delphi Tools menu.  If Delphi is already running, you won't see this on it's menu until you exit it and restart.

Installing the new component:

Select 'Install|Install new component' from the menu.  Delphi must be running for this item to be enabled.

Saving the component specifications:

To save the component specifications choose 'File|Save *.spc file' from the menu.  This does not create a useable output file but only saves the specifications for later retrieval.  Saved specifications include property, method and event handler definitions.

Retrieving component specifications:

From the menu choose 'File|Open *.spc file'.  Previously saved component specifications will be loaded from the spc file.


About This Help file

This help file is to get you started with Component Builder.  It is NOT a tutorial on how to write components.  If you're planning to write components for Delphi, you should be thoroughly familiar with the Component Writer's Guide that ships with Delphi.  Also the Component Writer's Help contains invaluable information that should be your standard reference when building a component.  This file does not attempt to explain such things as what is a virtual method, etc. and other technical details of component design.  Refer to the Guide for intricacies of component design.


Property Name

The property name can be any valid identifer. For example : Count