If you are a beginner “Hello World” examples are good to understand feature of that programming language. It is good to understand how to edit text, how to write in its format, how to compile and link, how to debug and execute, how to deploy or release.
This example below is a modern “Hello World” example on Windows which runs with C++ Builder. Modern applications has GUI and they should be compatible with other operating systems (Windows, MacOS, iOS, Android). FireMonkey projects are Multi Device (multi-platform) applications that you can compile and run on Windows, MacOS, iOS and Android .
“Hello World” with Memo Component
TMemo is good to display all outputs as in console applications.
– Open C++ Builder or RAD Studio IDE
– Create a new MultiDevice Application in C++ Builder from File menu
– Save all units and project files with “HelloWorld_” prefix in a HelloWorld folder.
– Add Memo and a Button from the Palette to your Form
– Double click to Button to create OnClick event, inside that Button1Click event write lines as below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include <fmx.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.fmx" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { UnicodeString ustr; ustr.printf(L"Hello, Pi is %8.3f",M_PI); Memo1->Lines->Add(ustr); } |
– Run project by hitting F9 or click to Run with Debugging
– If there is error, please check your lines
– If all is fine then save all project
– if you check your header file you will see all your objects (Memo, Button etc. ) are automatically defined as below. You don’t need to change anything here
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#ifndef HelloWorld_Unit1H #define HelloWorld_Unit1H //--------------------------------------------------------------------------- #include <System.Classes.hpp> #include <FMX.Controls.hpp> #include <FMX.Forms.hpp> #include <FMX.Controls.Presentation.hpp> #include <FMX.Memo.hpp> #include <FMX.Memo.Types.hpp> #include <FMX.ScrollBox.hpp> #include <FMX.StdCtrls.hpp> #include <FMX.Types.hpp> //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TMemo *Memo1; TButton *Button1; void __fastcall Button1Click(TObject *Sender); private: // User declarations public: // User declarations __fastcall TForm1(TComponent* Owner); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif |
Design. Code. Compile. Deploy.
Start Free Trial
Free C++Builder Community Edition