User talk:Achursin

From RAD Studio
Jump to: navigation, search

Go Up to iOS Mobile Application Development

Go Up to Android Mobile Application Development

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
Desktop Applications

Component(s) to Use in
Mobile Applications

TMainMenu, TPopupMenu

TToolBar, TSpeedButton, TPopup

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

  1. Select the TToolBar component in the Tool Palette, and drop it on the FireMonkey Mobile Form Designer.
  2. Select the TSpeedButton component in the Tool Palette and drop it on the ToolBar.
  3. Select the Speed Button Component on the Mobile Form Designer, and then select buttonstylelabel in the StyleLookup property in the Object Inspector.
  4. Select the TPopup component in the Tool Palette, and drop it on the FireMonkey Mobile Form Designer.
  5. In the Structure View, make this TPopup a child of the TSpeedButton.
  6. Select the TLabel component in the Tool Palette, and drop it on the FireMonkey Mobile Form Designer.
  7. In the Structure View, make this TLabel a child of the TPopup.
  8. Select the TLabel, and in the Object Inspector, set the HitTest property to True.

Note: To add several labels, repeat Steps 6 to 8.

StructureView.png

  1. 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;
    }
    
  2. For each TLabel component that you have added to the TPopup, implement the appropriate onClick event handlers.

<TO BE Continued>