Site icon Learn C++

How to Use Powerful Form Methods in Cross-Platform C++ Apps

In this post, you’ll learn about the available form methods, as well as how to use mouse events on forms. How can we capture and analyze key presses on forms? By learning form methods on FireMonkey Applications, it will help you to build C++ applications with the use of C++ software.

C++ Builder makes writing C++ programs a lot easier

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. It is the oldest IDE (it began as Borland TurboC in 1990 and was later renamed Borland C++ Builder). Under the Embarcadero brand it comes with new versions, features, updates and support. 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.

Forms (TForm) in FMX Framework and Its Methods

TForm represents a standard FireMonkey application window form. When we create forms in the Form designer at design time, they are implemented as descendants of TForm. Forms can represent the application’s main window, or dialog boxes, or various preferences-related windows. A form can contain any other FireMonkey objects, such as TButtonTCheckBoxTComboBox objects, and so on. All the Properties of Forms in the FireMonkey framework can be found here and Methods of Forms can be found here in official DocWiki.

We can use Hide() and Show() methods to hide and show our forms.

[crayon-67632f54ce7a9534652017/]

We can use SendToBack() and BringToFront() methods, to send our form to the back or to bring to front.

[crayon-67632f54ce7d0634890846/]

We can use Deactivate() or Activate() methods to activate or deactivate event dispatcher.

[crayon-67632f54ce7d3579570217/]

We can use Close() or CloseModal() to close forms and we can also delete all form properties with Free() method.

[crayon-67632f54ce7d4447126407/]

Using Events of Forms (TForm) in FMX

One of the great feature of FireMonkey framework is events of components, these are methods that can be created by double clicking on the events of Object Inspector. Forms also has a lot of events.
To create and do something in a event of Form;

  1. Select Form
  2. Go to Object Inspector and Press Events Tab
  3. Double Click to value of event that you want to use, this will create this event in header file and method will be added in your cpp file automatically.
  4. Now you can add whatever you want to in that event

Here below screenshot example, we double click most of events of form and we added some codes in their procedures (methods).

Using Mouse Events of Forms (TForm) in FMX

For example we can use OnMouseDown(), OnMouseMove(), OnMouseUp() events to detect mouse button clicks with X and Y coordinates, and mouse wheel delta as below;

[crayon-67632f54ce7d6942038532/]

Using Keyboard Events of Forms (TForm) in FMX

Here are the FormKeyDown() and FormKeyUp() keyboard examples below.

[crayon-67632f54ce7da890118053/]

Using Other Events of Forms (TForm) in FMX

Here is a full FMX example that has most of events are tested as below,

[crayon-67632f54ce7dc515009846/]

These methods shows how C++ Builder is capable to handle all of events of form windows. These methods may improve your applications, allows users to have better and faster user experience.

There are many methods and properties that we can use. All the Properties of Forms in FireMonkey frame work can be found here and Methods of Forms can be found here in official DocWiki.

Exit mobile version