In this article we will add some quick methods to show how to use basic components in C++ Builder. Most of component properties and methods are same in VCL and FMX projects. If you are a beginner we highly recommend you to watch this Introduction To C++ Windows Development With C++Builder video to understand C++ Builder / RAD Studio IDE interface and some basic mechanisms. This video will help you how to create simple C++ Builder projects. So you can easily adapt these quick looks to your projects.
In these examples below we primarily use FireMonkey components and samples, VCL components are mostly same in most conditions.
Table of Contents
TButton
TButton is a button component allows you to add what your application will do when pressed or not. Methods, properties and events of this component can be found here in VCL or here in FMX form.
Palette window (at the right bottom side of C++ Builder) has all components installed. You can drag Button component from Palette Window under the Standard category.
OnClick Event of Button
The most used action of Button is OnClick event, it is being auto created by using double click on it. Or you can select your button and, go to Events Section of Object Inspector, Double click to OnClick event will generate a procedure, add missing lines inside as below;
1 2 3 4 5 6 |
void __fastcall TForm1::Button1Click(TObject *Sender) { ShowMessage(L"Hello Developer"); } |
TLabel
Used to show text information or variables. A TLabel component (class) shows a text on your forms. When your application runs the user cannot edit this text.
Setting Labels
Labels can not be edited by user directly, you can easily change text of selected label from Text FMX Property (or Caption in VLC Property) in Object Inspector.
1 2 3 4 5 6 7 8 9 10 11 12 |
Label1->Text=L"Hello Developer"; UnicodeString ustr=L"Hello World"; Label1->Text=ustr; UnicodeString ustr2; ustr2=Label1->Text; int i=5; Label1->Text=IntToStr(i); // Integers values needs to be converted to text to be displayed |
TEdit
As same in label you can easily change text of selected Edit from Text FMX and VCL Property in Object Inspector.
1 2 3 4 5 6 7 8 9 |
Edit1->Text=L"Hello Developer"; UnicodeString ustr=L"Hello World"; Edit1->Text=ustr; UnicodeString ustr2; ustr2=Edit1->Text; |
TMemo
It is a multiline text editing control, providing text scrolling, you can use it as a output component like command prompt. To do this you must use Add(” “) method.
1 2 3 |
Memo1->Lines->Clear(); Memo1->Lines->Add(L"Hello Developer"); Memo1->Lines->Add(L"Hello World"); |
Lines of Memos are StringList and it is very easy to load or save a text in it;
1 2 3 4 |
Memo1->Lines->LoadFromFile("D:\\test.txt"); Memo1->Lines->SaveToFile("D:\\test.txt"); |