Site icon Learn C++

How to Create a New 64bits VCL Component in C++ or Delphi

How can I create a new 64bits VCL Component? How can I use the New Component menu? How can I use and fill the New Component Wizard for the 64bits VCL applications? What is a Component in C++? What is an Object in C++? Let’s answer these questions.

Note that this article uses C++ Software for its example, but the process for Delphi applications is exactly the same.

One of the most powerful features of the C++ Builder is its own Components that can be used with or without visuals. Components make programming easy; you can do many operations easily without knowing low coding or some specific features needed. Every component that you drag into is an object of that component class. For example, TEdit is a Class Type, a Component and Edit1 is an Object from the TEdit Component.

RAD Studio runs in 32bits, which means all design-time components should be 32bits. You can compile a 64bits VCL Component but you can NOT install a 64bits design-time VCL Component on to 32bits RAD Studio. On the other hand, you can create a 32bits VCL component that runs with your 64bbits applications. That means while the RADS IDE is 32bits, you can create 64bits applications with your 64bits components. Now let’s see how we can do this.

What is a Component in C++/Delphi?

In C++ Builder and Delphi, every object (i.e. Edit1) inherits from TObject class (i.e. TEdit1). Objects that can appear in the Form Designer inherit from TPersistent or TComponent Controls, which appear to the user at run time, inherit from TControl. There are two types of controls, graphic controls, which inherit from TGraphicControl, and windowed controls, which inherit from TWinControl. A control like TCheckBox inherits all the functionality of TObjectTPersistentTComponentTControl, and TWinControl, and adds specialized capabilities of its own.

A Component in C++ Builder and Delphi specifies the base class for all components. Components can be added to the Tool palette and manipulated at design time. Components can own other components. Com

The TComponent branch contains classes that descend from TComponent but noTControl. Objects in this branch are components that you can manipulate on forms at design time but which do not appear to the user at run time. They are persistent objects that can do the following:

Several methods introduced by TComponent dictate how components act during design time and what information gets saved with the component. Streaming (the saving and loading of form files, which store information about the property values of objects on a form) is introduced in this branch. Properties are persistent if they are published and published properties are automatically streamed.

The TComponent branch also introduces the concept of ownership, which is propagated throughout the component library. Two properties support ownership: Owner and Components. Every component has an Owner property that references another component as its owner. A component may own other components. In this case, all owned components are referenced in Components property of the component.

The constructor for every component takes a parameter that specifies the owner of the new component. If the passed-in owner exists, the new component is added to Components list of that owner. Aside from using the Components list to reference owned components, this property also provides for the automatic destruction of owned components. As long as the component has an owner, it will be destroyed when the owner is destroyed. For example, since TForm is a descendant of TComponent, all components owned by a form are destroyed and their memory freed when the form is destroyed. (Assuming, of course, that the components have properly designed destructors that clean them up correctly.)

If a property type is a TComponent or a descendant, the streaming system creates an instance of that type when reading it in. If a property type is TPersistent but not TComponent, the streaming system uses the existing instance available through the property and reads values for the properties of that instance.

Components that do not need a visual interface can be derived directly from TComponent. To make a tool such as a TTimer device, you can derive from TComponent. This type of component resides on the Tool Palette but performs internal functions that are accessed through code rather than appearing in the user interface at run time.

Components,Packages and Libraries for 64bits Applications

64bits Windows Components, Packages, and Libraries Require 32-bit Design-Time Versions

If you are creating 64-bit Windows components, packages, or libraries, you need to have 32-bit Windows design-time versions of these if you want to use these components, packages, and libraries in the IDE during application development. This requirement exists because the IDE is a 32-bit Windows program.

For example, if you are using the New Component wizard, you need to start by creating a 32-bit Windows version of your component. Later you compile your component again, as a Win64 component, by setting the Target Platform to be 64-bit Windows (in the Projects Window). RAD Studio saves output files (such as .bpl and .dcp) in platform-specific directories located inside your project output directory.

64bits Windows application development

How to use the “New Component” Wizard?

We can use New Component Wizard to create a new component for Delphi or C++Builder. The personality of your current project is detected and used for the component.

  1. Create a folder for your component (i.e. on the Desktop create a “MyVCLComponent” folder)
  2. Select New Component… from Component menu of RAD Studio or C++ Builder as below

3. New Component Wizard will help you to create your component. In the first windows, to create a VCL component choice VCL for C++ Win32.

then Press “Next>>” button.

4. Now we can choice an ancestor component. In this list, you will see that you can choice all official components and installed components as an ancestor.

For a general control component you can choice TControl or for example if your want to create your own Edit (TEdit) box including its features you can choice TEdit. For a custon Button (TButton) you can choice Button etc.

In our example, we will make a custom animating Image component. So let’s search TImage from the search. Select TImage and then Press “Next>>” button.

5. In this step we should add Class Name to our component. This Class Name should start with T. T represents the Class Type. Let’s name our component as TMyVCLComponent. We can choice a category from the Palette Name or we can add a new Category. Let’s add a new category MyNewCategory. We should add A Unit name, Unit file name should be different from the Class Name and it should be full path in our component folder. In our example Unit Name can be “C:\Users\<UserName>\Desktop\MyVCLComponent\MyVCLCompo1.cpp“. Wizard should be like this in accordance with your user name:

So In our example we used:

Class Name : TMyVCLComponent
Palette Name: MyNewCategory
Unit Name: <Folder Path\>”MyVCLCompo1.cpp” for example here “C:\Users\ata\Desktop\MyVCLComponent\MyVCLCompo1.cpp

and then Press “Next>>” button.

6. We will create a new package so, select Install to New Package and then Press “Next>>” button.

7. Now we should add Full Package Name. Do not enter name, your project file should be in your MyVCLComponent Folder. Note that Package name shouldn’t be as same as Class name. For Example it could be “C:\Users\ata\Desktop\MyVCLComponent\MyVCLCompo2021.cbproj” as below

8. Select Finish Button.

9. Now it will ask where to save “MyVCLCompo1.cpp” file select our MyVCLComponent folder and keep file name same, and press Save button.

If you see a confirmation as below select Yes.

10. Now it should compile your first VCL component. When done you should see this message below.

11. After pressing OK you may see it is asking where to save its PCH file, select the same MyVCLComponent folder

12 Now you can Install your components by selecting Install from the right click menu over the “MyVCLCompo2021.bpl” file in your Project Group

For the any new changes you can check DocWiki about the Using the New Component Wizard

How do I test my new VCL component?

  1. Create a new C++ Builder Windows VCL Project
  2. On form design mode, in your palette you will se MyNewCategory you will see TMyVCLComponent. You can drag your new custom component to you form.

3. Now you can compile your project with your new component by pressing Run or F9. Note that you need your MyVCLCompo1.h so if your project asks select the header file location or add it to a include path. You can select as below and press OK button.

C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.

Exit mobile version