1. Home
  2. Computing & Technology
  3. Delphi Programming

Fake Creating a New Delphi Control
The Fastes Way to Create a Captionless Panel

By Zarko Gajic, About.com

Component Template Dialog in Delphi

Component Template Dialog in Delphi

Even the birds know that Delphi is a great tool when custom component creation is in question.

Experienced Delphi developers, when they need a "non-existing" control (exposing some specific functionality), would either look for a third-party VCL solution or would try creating a new control from scratch.

What most beginners do not know is that they *can* create their own custom controls derived from the existing VCL set, by using component templates.

Let's consider the TPanel Delphi control - you use it to put an empty panel on a form - then drop other controls on it. Thus, a panel is mostly used as a container control.

When you drop a Panel on a form, it will, by design, have a default Caption set to something like "Panel1". I myself, in 99.99% cases, have to clear out the caption before adding any controls to it - I simply do not need a caption on a panel.

Therefore, here's how to "fake" creating your own Panel control that has an empty caption by design.

Captionless Panel

Here's what to do:
  1. Have an empty Delphi form,
  2. Drop a TPanel on it. It will have "Panel1" for its Caption,
  3. Clear out the caption property in the Object inspector,
  4. Change any any other properties as needed - to "default" values for your panel,
  5. Select Component - Create Component Template. The "Create Component Template" will be displayed.
  6. Specify the name for your custom "fake" control. Default will be "TPanelTemplate". Specify the palette page. Click ok.
  7. Locate the "Templates" palette on the tool palette. There's a new "TPanelTemplate" component.
  8. Drop it on a form - note that there's no caption!
Note that if you have already specified some event handlers for the Panel (before step 4.) like "OnClick" - when you drop a "TPanelTemplate" on the form - it will have the OnClick even handler already specified.
Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. Creating VCL components
  6. Fake Creating a New Delphi Control - Captionless Panel

©2009 About.com, a part of The New York Times Company.

All rights reserved.