• Blog
  • Simple custom visual component for Delphi: how to create

Simple custom visual component for Delphi: how to create

The Visual Components Library

Publish date:
Discover more of what matters to you

If you are familiarized with the Delphi app development process, you definitely know that it is based on the components methodology which ensures seamless and fast creation of applications. Such a methodology presupposes that Delphi apps are composed of separate “bricks” that are known as components.

Delphi components can be classified based on different parameters. For example, based on the type of representation, we can name visual and non-visual components. The first group includes those components that will have a representation in the UI, such as buttons, images, and other visual elements. Those elements that won’t be represented in the UI are referred to the second group.

In this article, we will take a closer look at the Visual Components Library and will consider cases when you will need to create a custom visual component.

Visual Component Library: what is it?

The Visual Component Library (VCL) provides a wide range of non-visual and visual controls and components that developers use to create practically any UI that they want. The fundamental elements of this library are objects and all the controls and components are based on objects.

The components that are presented in this library allows building Windows native applications.

The standard set of components available in the VCL is composed of all the controls that are offered in the Windows UI framework. The components included are edits, menus, buttons and others. Moreover, the VCL also contains some additional components that are not provided by the Windows UI framework. Being an extension of the standard set, they offer additional functionality.

Custom visual component for Delphi: when do you need it?

If you build Delphi apps, you can use the existing components that are provided by Embarcadero or any other third-party vendors. However, sometimes you can see that those components that are available on the market are not relevant in your case. In such a situation, good news is that you can create a visual component on your own and ensure the functionality that is lacking in existing ones.

But it is not the only case when the development of a custom component can be a good idea.

For example, you can do that if you want to reuse the app logic as well as the code for your future projects.

Creating your own component, you can also deliver them to other developers with a source code on a commercial basis.

How to create a custom visual component for Delphi?

So, let’s suppose that you’ve decided to build a visual component on your own. What should you know before you start?

In this case, you will work with the same environment that is used for developing Delphi applications. However, there will be some serious differences that you should be aware of:

  1. First of all, end users will differ. Components will be used by developers, not by the people your apps are targeted at.
  2. There are three different interfaces of components. An app has only one runtime interface. In addition to this one, a component also has design-time and developer interfaces.
  3. Components should support a high level of flexibility in order to allow developers to use them the way they need to.
  4. Writing of components is a highly object-oriented and non-visual process that requires strong specific knowledge including a good understanding of the VCL peculiarities.

Though it may seem that it is a real challenge to build your own visual component, it is not so. It is nothing more than just programming.

There are several ways to create components, including modifying existing ones, deriving from the already available components, and creating them from scratch.

Components are classes that descend from other types of classes. When it comes to visual components, they basically descend from any of the following ones:

  • TGraphicControl
  • TWinControl
  • TCustomControl

The main steps that you need to perform whenever you want to build a component are:

  • to create a unit for it;
  • to derive a new component from an existing type;
  • to add methods, properties, events;
  • to register this component with the integrated development environment;
  • to create a bitmap for it;
  • to build a package that will ensure installation of the component in the IDE;
  • to create a Help file that will contain instructions for developers who will use this component (this step is optional, that’s why you do not have to do it if you consider it unnecessary).

One of the easiest ways to build a simple visual component is to use the New Component wizard. This tool makes the initial steps of component creation much simpler. To initiate the process, you need to specify a row of parameters including the class from which your component will be derived, the class name, the unit where the component will be created and some others.

If you are going to write a visual component, you need to do the following things:

  1. To start the New Component wizard.
    There are 2 ways to do it. The first one presupposes choosing Component and the New Component.
    Or you can find File > New > Other, then opt for Delphi Projects, go to the Delphi Files page and choose Component.
  2. To indicate the data in the New Component wizard field.
  3. To choose the type of your future component (Delphi) on the Personality, Framework and Platform page.
  4. To choose the class that you want to use for deriving on the Ancestor Component page.
  5. To specify the name of the component class to be created. It should be done on the Component page.
  6. To go to the Palette Page and to indicate the Tool Palette category where your component should be installed.
  7. To specify the name of the unit of your component in the relevant field as well as to provide the details for the Search Path field if it is applicable
  8. To click the Finish button. For placing your component in the package regardless of the fact whether it is new or existing, it is necessary to click Component and then Install.
  9. To specify a package in the dialog box and click OK. A new unit will be created.

A more detailed step-by-step plan with further stages you can find on the website managed and supported by Embarcadero.

As you see, it is possible to create a custom component on your own but there is also a possibility for you to save your time and rely on professionals in this situation. At Softacom, we offer a wide range of components development services, including their creation, migration, enhancement and re-engineering. If you have any questions or any ideas that are already waiting for being implemented, just contact our team.

Subscribe to our newsletter and get amazing content right in your inbox.

This field is required
This field is required Invalid email address

Thank you for subscribing!
See you soon... in your inbox!

confirm your subscription, make sure to check your promotions/spam folder

Subscribe to our newsletter and get amazing content right in your inbox.

You can unsubscribe from the newsletter at any time

This field is required
This field is required Invalid email address

You're almost there...

A confirmation was sent to your email

confirm your subscription, make sure to check
your promotions/spam folder