User talk:Achursin
Go Up to iOS Mobile Application Development
Go Up to Android Mobile Application Development
Contents
This topic describes how to migrate existing C++ desktop code to use the C++ mobile compilers:
- C++ Compiler for iOS devices (BCCIOSARM.EXE)
- C++ Compiler for Android devices and emulators (BCCAARM.EXE)
Peculiarities of C++ Mobile Code
There are some peculiarities that you should consider when developing your C++ mobile applications or when migrating C++ desktop code to mobile code.
Type Casting
In some cases, C++ mobile does not support C-like casting. For example, the following code snippet is wrong:
void Callback(void* p) {
((TButton*)p)->Enable = true;
}
In this example, you should use the reinterpret_cast
operator instead. The reinterpret_cast
operator converts any pointer type to any other pointer type, even of unrelated classes. To use the above code snippet for C++ mobile apps, it should be reworked as follows:
void Callback(void* p) {
reinterpret_cast<TButton*>(p)->Enable = true;
}
Using the delete Operator
Let us consider that your code contains the delete
operator:
delete ptr
where ptr
is a pointer to the memory block to be released, type-casted to a void*
.
Please note, that in C++ mobile, the delete
operator does not always call an object destructor. The destructor is called only if there are no other pointers that refer to this object.
Eliminate FireMonkey Components that Are Not Supported by C++ Mobile Compilers
[TBD: Describe here all FireMonkey components that are supported for desktop apps, but cannot be used for C++ mobile apps. Explain, how to replace these components with other similar components.]
Component Used in |
Component(s) to Use in |
---|---|
TBD |
TBD |
TBD |
TBD |
TBD |
TBD |
TBD |
TBD |
Details follow about replacing these unsupported types.
TMainMenu or TPopupMenu
The mobile applications cannot use these components. To migrate your C++ desktop code to mobile, you should remove TMainMenu or TPopupMenu from your code and use the TToolBar, TSpeedButton and TPopup components instead.
To create a menu that uses TPopup
- Select the TToolBar component in the Tool Palette, and drop it on the FireMonkey Mobile Form Designer.
- Select the TSpeedButton component in the Tool Palette and drop it on the ToolBar.
- Select the Speed Button Component on the Mobile Form Designer, and then select buttonstylelabel in the StyleLookup property in the Object Inspector.
- For more detail about selecting a style in FireMonkey mobile applications, see Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android).
- Select the TPopup component in the Tool Palette, and drop it on the FireMonkey Mobile Form Designer.
- In the Structure View, make this TPopup a child of the TSpeedButton.
- Select the TLabel component in the Tool Palette, and drop it on the FireMonkey Mobile Form Designer.
- In the Structure View, make this TLabel a child of the TPopup.
- Select the TLabel, and in the Object Inspector, set the HitTest property to
True
.
Note: To add several labels, repeat Steps 6 to 8.
- In the Code Editor, for the TSpeedButton component, implement the following onClick event handler:
void __fastcall TForm1::SpeedButton1Click(TObject *Sender) { // Open the pop-up window. Popup1->IsOpen = True; }
- For each TLabel component that you have added to the TPopup, implement the appropriate onClick event handlers.
<TO BE Continued>