The C++ Builder CE Community Edition is a free version of professional C++ Builder that you can develop GUI based desktop and mobile applications in C++. In this post, we will give you five simple C++ console examples to help you understand how C++ Builder 11 CE runs applications.
The latest C++ Builder 11 CE was released in April 2023. If you are a start-up developer, student, hobbyist or just interested in learning to code then C++ Builder Community Edition may well be just the thing for you. Read the FAQ notes on the CE license and then simply fill out the form and download C++ Builder 11 CE.
If you download C++ Builder Community Edition (or RAD Studio CE version) or any Professional, Architect, Enterprise versions of C++ Builder. Install it on your windows computer and run RAD Studio or C++ Builder. Beginners and students normally start to learn C++ with simple code. Let’s create a new C++ application for Windows by using VCL framework in C++ Builder CE.
Table of Contents
How to develop C++ VCL applications in C++Builder CE?
If you download and install the C++ Builder CE Community Edition then we can start to coding,
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. VCL applications focus only Windows, if you want to develop same app for multiple-OS’es you can use FMX. Let’s start to develop a C++ app with GUI using VCL framework.
1. Choose File->New-> “Windows VCL Application – C++ Builder” menu.
This will create a New C++ Project for Windows. This will allow you develop C++ apps with VCL UI elements. If you don’t need UI Elements, this means you don’t need VCL or FMX frameworks, you create a console application too. Modern applications have a GUI’s and skinned Styles. Note that VCL projects are Windows only and FireMonkey projects are Multi Device (multi-platform) applications that you can compile and run on Windows, MacOS, iOS and Android.
2. Save all Unit files and Project file to a folder.
3. Drag components to your form design
Simply drag and drop components from the Palette window on the right side; Memo (TMemo) and Button (TButton) to your form design. Arrange their width, height and position. You can edit each of their properties from the Object Inspector on the left side.
Note that you can switch between the GUI Design mode to Code Mode by pressing F12, or vice versa. If you want, you can switch to your header file (.h) of your cpp file (.cpp) from the button tabs. You can change your Build Configuration from the left Project window by setting it to Debug or Release mode.
4. Double click to Button1 to create OnClick() event for this button. Add these lines into Button1Click() event, between { and } brackets as given below,
This example above is a modern “Hello World” example for Windows which runs with C++ Builder.
5. Now you can compile this C++ code; just press the F9 key or just click the Run button in the center of top bar. This will let the IDE check your code and compile both the Unit and project files and link them together. You can also use the Run menu from the top to run your application. You should see this below as a form application
If you get an error, check your code – it’s easy to mistype or have the braces (“}” characters) in the wrong place. Note that C++ is case sensitive, so upper and lower characters should be also same. Then press the F9 key or just click the Run button again.
You can change the font property of Memo, here we used Consolas 9 font that has fixed width.
From this point, you can add more codes or you can switch back to design mode by pressing F12. And you can add more components, then more code. This is how modern C++ coding works with an UI Toolkit.
How to do calculations in C++ VCL applications?
As in same example above, now lets do another simple calculation. We have a price of a product and there is VAT percentage, then we want to calculate total price of this product. To do this, we should set price and VAT, then we can calculate VATprice and at the final we need to print price and VATprice as a total to the Memo as below,
Now you can compile this C++ code; just press the F9 key or just click the Run button in the center of top bar. This will let the IDE check your code and compile both the Unit and project files and link them together.
How to enhance C++ VCL applications with C++Builder CE?
As in the same example above, now lets do a simple calculation. We have a price of a product and there is VAT percentage, then we want to calculate total price of this product. To do this, we should set price and VAT, and we need to calculate VATprice and totalprice too. So we can define these variables below,
We can define a UnicodeString
to set formated texts, then we can print this. UnicodeString has a printf function in modern C++ as in classic C function. Thus, we can print inputs and calculate totalprice as below,
Now you can compile this C++ code; just press the F9 key or just click the Run button in the center of top bar. This will let the IDE check your code and compile both the Unit and project files and link them together. You can also use the Run menu from the top to run your application. You should see this below as a form application.
How to accept input in C++ VCL applications?
Lets continue to same example. Let’s add more components to get inputs from user. Todo this, drag 2 Labels (TLabel) and 2 Edits (TEdit) components, and we will have a Memo (TMemo) and a Button (TButton) as below,
Double click to Button1, first we need to define our variables. Then we can get the price and VAT values from the Text of Edit1 and Edit2. We should convert Text to float values by using StrToFloat() function as below,
and other calculations and printing will be same as examples above. Thus, all Button1Click() event will be as below,
Now you can compile this C++ code; just press the F9 key or just click the Run button in the center of top bar. This will let the IDE check your code and compile both the Unit and project files and link them together. You can also use the Run menu from the top to run your application. You should see this below as a form application. This time our application is able to calculate different values.
How to use loops in C++ VCL applications?
We can create another example to calculate the price of many different product counts. Here is how you can use for() loop,
Now you can compile this C++ code; just press the F9 key or just click the Run button in the center of top bar. This will let the IDE check your code and compile both the Unit and project files and link them together. You can also use the Run menu from the top to run your application. This time our application is able to calculate different values of counts in a loop. You should see this below as a form application.
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 version.