Learn C++

What You Need To Compile Delphi Projects in C++ Builder

What You Need To Compile Delphi Projects in C++ Builder

Do you know you can use Delphi or Pascal files in your C++ applications?

RAD Studio is a very powerful IDE that comes with Delphi and C++ Builder. Delphi uses a version of the Object Pascal programming language while C++ Builder uses mainly C++. If you have Rad Studio you can easily use Delphi functions in your C++ Projects.

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. C++ Builder comes with Rapid Application Development Studio, also known as RAD Studio, and C++ Builder is one of the most professional IDE’s that work under RAD Studio. C++ Builder followed in the footsteps on the hugely popular Borland TurboC. Under the Embarcadero brand it expanded on the early days of TurboC to add tons of new features. 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.

You can download the free C++ Builder Community Edition here: https://www.embarcadero.com/products/cbuilder/starter.
Professional developers can use the Professional, Architect or Enterprise versions of C++ Builder. Please visit https://www.embarcadero.com/products/cbuilder.

How to compile Delphi projects in C++ Builder?

First, let’s create a new Pascal file.

  1. Create a new pascal file (i.e. pascal_example.pas)
  2. Add unit name as same as this file name (here we should use ‘unit pascal_example’). Note that this should be same as file name.
  3. Let’s assume that this pascal file has mypascal_function() and we want to use it in our C++ Builder project. Pascal file should be like this,

pascal_example.pas

Now create a new C++ Console app

  1. Create a new C++ Builder Console Project (cpp_example.cpp) and save all files into a folder
  2. Let’s simplify our C++ file as below

3. Press add file to project (or Shift+F11) to add pascal unit that we generate as above.
4. Now we should modify our C++ file. We should imports pascal unit so we can call it our our main() procedure as below,

Thus our C++ file should be as below

cpp_example.cpp

5. C++ Builder auto generates ‘pasacal.example.hpp’ header file for this pascal unit as below,

pascal_example.hpp

6. Now we can compile and run our project.

Is there an alternative method to compile Delphi programs in C++?

Another method to combine these files is running RAD Studio Command Prompt and compiling and linking files by using compiler commands and their options. In this method you must professionally know options and using compiler commands well. After doing steps in A and B Sections;

  1. Run RAD Studio Command Prompt
  2. Goto your project folder
  3. Type this command to console to compile pascal file as below,

4. Type these commands below to compile cpp file,

5. Now you can run your executable by typing cpp_example.exe , here is the output.

Here is a third way to compile Delphi programs using C++ Builder

We can also use the RAD Studio Command prompt.

You can write these commands described in section C to a .bat file (which is called DOS batch file). Thus you can run this bat file to compile and link all with a one build command. To do this, After doing section A and B steps, create a new text file which name has build.bat ( !be sure that it is not build.bat.txt) and write all commands that we do inside as below

build.bat

To compile both cpp and delphi (pas) files;

  1. Run RAD Studio Command Prompt
  2. Go to your project folder which has codes above
  3. run ‘build.bat‘ to compile both .pas and .cpp files into cpp_example.exe
  4. run ‘cpp_example.exe’ ,

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++

Learn Copy Constructors in C++ Classes

C++C++11C++14C++17Introduction to C++Learn C++Syntax

Learn How To Use Types Of Destructors In C++?

C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

C++C++11C++14C++17C++20Introduction to C++Learn C++

How To Learn The Move Constructors In Modern C++?