Embarcadero - Mobile Tutorials
Embarcadero - Mobile Tutorials
Embarcadero - Mobile Tutorials
RADStudio
Mobile Tutorials
Version Seattle
Embarcadero Technologies
CONTENTS
Mobile Tutorials: Mobile Application Development (iOS and Android) ................. 11
Setup ................................................................................................................................. 11
Using Basic User Interface Elements ............................................................................. 12
Using Device Functionality ............................................................................................ 14
Using Backend as a Service .......................................................................................... 15
Accessing a Database .................................................................................................. 15
See Also......................................................................................................................... 16
Mobile Tutorial: Set Up Your Development Environment on the Mac (iOS) .......... 17
Requirements on the Mac and iOS .......................................................................... 17
Steps to Configure Your Mac to Run Your iOS Application .................................. 17
Step 1: Install the Platform Assistant ...................................................................... 18
Step 2: Run the Platform Assistant ......................................................................... 19
Step 3: Install Xcode on the Mac .......................................................................... 20
Next Steps ................................................................................................................. 21
Additional Steps to Configure Your Mac to Run Your iOS Application on Your iOS
Device............................................................................................................................... 21
Step 1: Make Sure that the Xcode Command Line Tools Are Installed on Your
Mac ............................................................................................................................... 22
Step 2: Sign Up for a Developer Account ............................................................... 23
Step 3: Request, Download and Install Your Development Certificate ............. 23
Request, Download and Install Your Certificate ................................................ 23
Step 4: Register Your Device for Deployment......................................................... 25
Step 5: Create and Install a Provisioning Profile ..................................................... 25
See Also......................................................................................................................... 27
Mobile Tutorial: Set Up Your Development Environment on Windows PC (iOS) ... 28
Setting Up Your RAD Studio Environment ................................................................ 29
Create a Connection Profile for the Mac ........................................................... 29
Add an SDK to the Development System for the iOS Device Connected to
the Mac..................................................................................................................... 31
See Also......................................................................................................................... 33
Mobile Tutorial: Set Up Your Development Environment on Windows PC
(Android) .......................................................................................................................... 34
Setting Up Your RAD Studio Environment ................................................................ 34
Android Development Tools Are Installed with RAD Studio .............................. 35
Adding Your Android SDK in Tools Options > SDK Manager ............................. 36
Installing the USB Driver for Your Android Device (Required) ............................... 40
See Also......................................................................................................................... 41
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
........................................................................................................................................... 42
Before You Start ........................................................................................................... 42
Step 1: Create a New FireMonkey Application for Android or iOS ..................... 42
Embarcadero Technologies
Embarcadero Technologies
10
After the three initial setup tutorials, the first tutorial shows you how to
construct an iOS or Android application using FireMonkey tools.
Setup
Embarcadero Technologies
11
Embarcadero Technologies
12
Embarcadero Technologies
13
Embarcadero Technologies
14
Accessing a Database
Embarcadero Technologies
15
Accessing a Database
See Also
o
Multi-Device Preview
Embarcadero Technologies
16
The first half of this tutorial describes the steps that you need to perform in
order to run your iOS application (Delphi only) on the iOS Simulator on the
Mac.
The second half of this tutorial describes additional steps required in order
to run your iOS application (Delphi or C++) on your iOS Device.
Note: The iOS Simulator is not supported by BCCIOSARM, the C++ Compiler for
the iOS Device. Only iOS devices are supported by BCCIOSARM.
10.9 Mavericks
10.10 Yosemite
For iOS development, the latest version of the iOS SDK and Xcode
installed, along with the Xcode command line tools.
Note: RAD Studio does not support versions of the iOS SDK lower than 8.0.
o
An iOS device connected to the Mac by USB port (required for testing or
running your iOS app on the device)
17
RAD Studio uses the Platform Assistant to run and debug multidevice applications and to deploy multi-device applications on
Mac OS X and iOS devices.
Xcode
Xcode is the development and debug environment on the Mac and provides
the required development files for Mac OS X and iOS applications.
C:\Program Files
(x86)\Embarcadero\Studio\17.0\PAServer\PAServer17.0.pkg
o
http://altd.embarcadero.com/release/studio/17.0/PAServer/PAServer17.0.p
kg
Embarcadero Technologies
18
The Terminal window appears, displaying the Platform Assistant banner and the
password prompt:
Connection Profile password <press Enter for no password>
Either press Return, or enter a password for PAServer and then press Return.
3. Next you are prompted to enter your Mac user password to allow the
Platform Assistant to debug (take control of another process) your
application.
Embarcadero Technologies
19
For more details about running the Platform Assistant, see Running the Platform
Assistant on a Mac.
Embarcadero Technologies
20
Additional Steps to Configure Your Mac to Run Your iOS Application on Your iOS Device
Next Steps
You have configured your Mac to run an iOS application on the iOS Simulator.
Note: Only Delphi applications can be run on the iOS Simulator.
C++Builder does not support the iOS Simulator.
o
iOS Simulator: To run an iOS application (Delphi only) on the iOS Simulator
on the Mac, you do not have to complete the second half of this tutorial.
Instead, you can now go on to the next tutorial (Mobile Tutorial: Set Up
Your Development Environment on Windows PC (iOS)) to complete the
configuration of your RAD Studio IDE.
Remember that your iOS device should be connected to your Mac via USB
cable.
Embarcadero Technologies
21
Additional Steps to Configure Your Mac to Run Your iOS Application on Your iOS Device
5. If the Xcode Command Line Tools are not installed, the Command Line
Tools do not show the Xcode version.
Embarcadero Technologies
22
Additional Steps to Configure Your Mac to Run Your iOS Application on Your iOS Device
Embarcadero Technologies
23
Additional Steps to Configure Your Mac to Run Your iOS Application on Your iOS Device
Save the certificate request as a CSR file, and then send it to your Certificate
Authority through the iOS provisioning portal in the following way:
1. When prompted, enter your Apple ID and password, and then click
Sign In.
2. Under iOS Apps, click Certificates.
3. On the page that opens, click the plus sign (+) icon.
This opens the Add iOS Certificate wizard.
4. On the Select Type page, click Continue and follow the onscreen
instructions to proceed with the wizard.
5. When prompted, upload the CSR file that you saved on your Mac.
2. Go to iOS Provisioning Portal. You can download the Development
certificate clicking the Download button as shown below:
Embarcadero Technologies
24
Additional Steps to Configure Your Mac to Run Your iOS Application on Your iOS Device
After your provisioning profile is created, you must install it into Xcode, as follows:
o
Xcode5:
Embarcadero Technologies
25
Additional Steps to Configure Your Mac to Run Your iOS Application on Your iOS Device
1. Open Xcode on the Mac and go to the Organizer (Window > Organizer).
2. In the Library section, select Provisioning Profiles and click Refresh.
3. Xcode asks you to sign in with your Apple ID. Enter your credentials and
select Log in.
The provisioning profiles available to you are installed into your Xcode:
Xcode 6:
1. Open Xcode on the Mac and go to the Devices (Window > Devices).
2. Right-click the device and select Show Provisioning Profiles
Embarcadero Technologies
26
Additional Steps to Configure Your Mac to Run Your iOS Application on Your iOS Device
You have configured your Mac to run your iOS application on your iOS Device.
To run your iOS application, please see Mobile Tutorial: Set Up Your Development
Environment on Windows PC (iOS) and complete the configuration of your RAD
Studio IDE. (If you have configured your PC as part of running your application
on the iOS Simulator, you can skip this step.)
See Also
o
Create an Apple ID
Embarcadero Technologies
27
A FireMonkey application destined for the iOS target platform can be tested
initially on the iOS Simulator available on the Mac. The second half of the testing
process uses the iOS Device target platform and requires a test iOS device
connected to the Mac.
Note: On iOS devices, you can run both Delphi and C++ applications. However,
the iOS Simulator is not supported by BCCIOSARM, so only iOS devices are
supported for C++.
To deploy an iOS Application to your iOS device or iOS Simulator for debugging
and testing purposes, RAD Studio uses the Platform Assistant, which you must
install and run on the Mac. Your hardware and software development
environment should have the configuration demonstrated in the following figure.
RAD Studio runs on a Windows PC computer. Your PC computer should be
connected to a Mac running the Platform Assistant and having installed the
appropriate versions of Xcode and iOS SDK (for iOS development). To run iOS
apps on an iOS device, the iOS device must be connected via USB cable to the
Mac.
This section describes the steps to set up your development environment after
you configure your environment on your Mac.
Embarcadero Technologies
28
3. Now you see the Create a Connection Profile wizard. Define a name for
the connection profile, such as "My Mac".
Make sure you select OS X as the platform, and then click Next:
Embarcadero Technologies
29
Embarcadero Technologies
30
5. Click Test Connection, and make sure that the connection profile
succeeds with no error (you should receive the message "Connection to
<hostname> on port <portnumber> succeeded").
6. If the Test Connection succeeds, click the Finish button, otherwise check
the settings and try again.
2. Click Add.
3. On the Add a New SDK dialog box, select iOS Device - 32 bit or iOS
Device - 64 bit as a platform.
Embarcadero Technologies
31
4. After you select a platform, the IDE fills a Profile (such as "My Mac") and
SDK version combo box with the list of SDK versions available on the
machine where the Platform Assistant server is running:
Embarcadero Technologies
32
See Also
o
iAd Network
Embarcadero Technologies
33
Embarcadero Technologies
34
We recommend that you install the Android development tools using our
product installer. However, if you already have the Android development tools
installed on your system, or if you want to install the tools yourself, you can
choose to skip this step in the installer. For specific instructions on installing the
Android development tools yourself, see Installing the Android Development
Tools.
Default Location
C:\Program Files\Java\jdk1.7.0_25
Java
Developme
nt Kit (JDK)
C:\Users\Public\Documents\Embarcadero\Studio\17.0\PlatformSDK
Android
s\android-sdk-windows
Software
Developme
nt Kit (SDK)
C:\Users\Public\Documents\Embarcadero\Studio\17.0\PlatformSDK
Android
s\android-ndk-r9c
Native
Developme
nt Kit (NDK)
Embarcadero Technologies
35
If the Android SDK and NDK are installed during the RAD Studio installation,
your Android SDK should be automatically discovered by the RAD Studio
SDK Manager, and you do not need to perform this step. Proceed to the
next step: Installing the USB Driver for Your Android Device.
If you installed the Android SDK and NDK yourself, you need to perform this
step so that RAD Studio can build apps that target Android devices.
1. Select Tools > Options > Environment Options > SDK Manager.
Here is the SDK Manager when it is fully populated with the recommended
Android SDK:
Note:
The SDK Manager fields are blank if the SDK Manager cannot detect the
default installed Android SDK and you have not yet added an Android
SDK to the SDK Manager.
2. Click Add.
3. On the Add a New SDK dialog box, click the down-arrow in the Select an
SDK version field, and select Add New... from the drop-down list:
Embarcadero Technologies
36
Note: If your installed Android SDK is listed in the Select an SDK version list, select
your Android SDK.
4. The Create a new Android SDK wizard is displayed.
On this wizard, complete the first two fields: Android SDK Base Path
and Android NDK Base Path (their installed locations).
Either enter the paths of the installed locations or click the ellipsis [...] and
navigate to the installed locations.
The
symbol indicates that the base paths are missing, and the
Next button is enabled only after these fields are filled.
Here is the wizard when no SDKs have been added and the base
path fields are empty:
Embarcadero Technologies
37
This wizard verifies the base paths you specify and then auto-populates the paths
to the various other libraries (that is, the tools on page 2 of the wizard).
Thus, you might need to enter only the base paths for the NDK and SDK, on page
1 of the wizard. Then the second page will auto-populate, if given a little time. Or
you might need to verify the auto-populated addresses (if they are present).
There are no
Here is the first page of the wizard after you browse to (or enter) the
paths to the Android SDK and NDK.
icons because the paths have been verified.
Embarcadero Technologies
38
5. Click Next to go to the next page of the wizard, where the wizard will
attempt to prefill the fields by discovery.
Here is the second page of the wizard with all its fields prefilled:
For any fields that do not prefill, click the ellipsis [...] button and
browse to the installed location.
Embarcadero Technologies
39
You can view and manage your installed Android SDKs by opening the SDK
Manager.
For example, for a Nexus 7 or Nexus 10 tablet, you install the Google USB Driver
using the Android SDK Manager, as follows:
1. Start the SDK Manager.exe by selecting Start | Programs | Embarcadero
RAD Studio | Android SDKs | Android Tools:Start the SDK Manager.exe by
selecting Start | Programs | RAD Studio | Android SDKs | Android Tools:
Tip: If the Android SDK Manager does not start, run android.bat from the \tools
directory inside your installed SDK directory.
2. In the Android SDK Manager, install the USB driver for your Nexus 7 or
Nexus 10 :
1. Select Google USB Driver, clear all other checkboxes, and click
Install 1 Package:
Embarcadero Technologies
40
See Also
o
Embarcadero Technologies
41
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
Embarcadero Technologies
42
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
Embarcadero Technologies
43
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
2. iOS: If you want to create an iOS app, open the Target Platform
node in the Project Manager and double-click iOS Simulator (only
for Delphi) or a connected iOS device (for either Delphi or C++):
Note: When you select a platform, the components not available for this
particular platform appear grayed.
Embarcadero Technologies
44
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
7. After you place these components on the Form Designer, the IDE
automatically sets names for the components.
To see or to change the name of a component, click the component on the
Form Designer, and then find its Name property in the Object Inspector and the
Structure View:
For a TButton component, the component name is set by default to Button1 (or
Button2, Button3, depending on how many TButtons you have created in this
application).
8. The form on which these components are located also has a name.
Select the background of the Form Designer, and select the Name
property in the Object Inspector. The name of the form Form1 (or Form2,
Form3,...) is displayed. You can also locate the name of the form in the
Structure View:
Embarcadero Technologies
45
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
Note: Form names set by default as Form1, Form2, Form3,... are for the Master
views. Device views are named FormName_ViewName such as Form1_iPhone
(iPhone 3.5 form) and Form1_NmXhdpiPh (Android 4 Phone form).
9. You can easily switch to source code by selecting the Code (for Delphi) or
<unit name>.cpp/<unit name>.h (for C++) tab at the bottom of the Form
Designer. You can also press the F12 key to switch between the Form
Designer and the Code Editor:
Delphi
C++
The Code Editor displays the source code that the IDE has generated. You should
find three components defined (Edit1, Label1, and Button1):
Embarcadero Technologies
46
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
Delphi
C++
Note: When you save or run your project, the uses and include clauses are
updated (to add FMX.StdCtrls for TLabel and FMX.Edit for TEdit).
Embarcadero Technologies
47
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
Delphi
C++
C++ code:
Label1->Text = "Hello " + Edit1->Text + " !";
In Delphi, the quotation marks that surround string literals must be straight single
quotation marks (that is, 'string'). You can use the plus (+) sign to concatenate
strings. If you need a single quote inside a string, you can use two consecutive
single quotes inside a string, which yields a single quote.
While you are typing code, some tooltip hints appear, indicating the kind of
parameter you need to specify. The tooltip hints also display the kinds of
members that are supported in a given class:
Delphi
C++
Embarcadero Technologies
48
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
Delphi
C++
Embarcadero Technologies
49
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
When you run your application, it is deployed to the Mac and then to the iOS
Simulator on the Mac. For our app, a form with an edit box and a button is
displayed. Enter text into the edit box, and click the Say Hello button:
Note: On the iOS simulators, you can test only your Delphi applications.
Embarcadero Technologies
50
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
After you select the appropriate iOS Device target platform, run your iOS app by
clicking the Run button in the IDE, pressing F9 or selecting Run > Run.
On your Mac, you might see a dialog asking your permission to code sign your
iOS app. Select either "Always Allow" or "Allow" to sign your app.
Then go to your iOS device and wait for your FireMonkey iOS app to appear.
Watch for the FireMonkey launch image (the icon is available in
$(BDS)\bin\Artwork\iOS, and you can set the launch image in Application
Options):
Embarcadero Technologies
51
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
See Also
o
Mobile Tutorial: Using a Button Component with Different Styles (iOS and
Android)
Embarcadero Technologies
52
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
Embarcadero Technologies
Android
53
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
Android
Change the text displayed on the button surface by updating the value
of the Text property in the Object Inspector.
Change the value of the Position.X and Position.Y properties (or drag the
component using your mouse.)
Change the value of the Height and/or Width properties (or drag the
edge of the component using your mouse.)
In the StyleLookup drop-down list, you can select a predefined Style based on
how your component is to be used:
Embarcadero Technologies
54
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
Embarcadero Technologies
55
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
The TintColor and IconTintColor properties are only available in the Object
Inspector if you select a proper Style for the button and select a proper View in
the Form Designer (these properties are not visible in all Views).
For the Android target platform:
You can apply a tint to most buttons of any style:
o
For speed buttons, you need to select a proper StyleLookup value in order
to change the TintColor value in the Object Inspector.
When you change the StyleLookup property of a button, the Object Inspector
automatically displays or hides the TintColor and IconTintColor properties as
appropriate for the StyleLookup property value. The following image shows three
TSpeedButtons on an Android app:
Embarcadero Technologies
56
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
Set the Height and Width properties of TButton to the actual height
and width of your image.
Embarcadero Technologies
57
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
Android
Android
Android
Embarcadero Technologies
58
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
iOS
Android
5. Select each component, and change the Text property as you like:
iOS
Android
Android
Embarcadero Technologies
Android
59
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
toolbuttonleft
toolbuttonmiddle
toolbuttonright
(on the Android target platform set StyleLookup as toolbutton for each of the
buttons.)
iOS
Android
TSpeedButton cannot receive TAB focus. That also means that pressing a
TSpeedButton does not take away focus from other elements.
The style of TSpeedButton can be different than the style of TButton. For
example, on the Android platform, the default style of the TSpeedButton is
similar to the toolbutton style of the TButton. If you want a TSpeedButton
with a similar style to the TButton, choose the buttonstyle style.
See Also
o
FMX.Controls Sample
FMX.StdCtrls.TButton
Embarcadero Technologies
60
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
FMX.StdCtrls.TSpeedButton
FMX.Controls.TStyledControl.StyleLookup
FMX.StdCtrls.TToolBar
FMX.StdCtrls.TCustomButton.IconTintColor
FMX.StdCtrls.TCustomButton.TintColor
FMX.StdCtrls.TToolBar.TintColor
Embarcadero Technologies
61
Mobile Tutorial: Using a Calendar Component to Pick a Date (iOS and Android)
Android
iPad2
LG-E612
Embarcadero Technologies
62
Mobile Tutorial: Using a Calendar Component to Pick a Date (iOS and Android)
After you drop the component, you can see the TDateEdit component on the
Form Designer:
Optionally, in the Object Inspector, you can set the following properties of
TDateEdit:
Embarcadero Technologies
63
Mobile Tutorial: Using a Calendar Component to Pick a Date (iOS and Android)
Android (LG-E612)
Embarcadero Technologies
64
Mobile Tutorial: Using a Calendar Component to Pick a Date (iOS and Android)
C++Builder:
void __fastcall TForm25::DateEdit1Change(TObject *Sender)
{
ShowMessage(FormatDateTime("dddddd", DateEdit1->Date));
}
This code shows a message dialog with a date selected. The FormatDateTime
function converts the selected date to a specified format (in this case dddddd
gives long-style date format):
iOS (iPad)
Android (LG-E612)
See Also
o
Mobile Tutorial: Using a Button Component with Different Styles (iOS and
Android)
Mobile Tutorial: Using Combo Box Components to Pick Items from a List
(iOS and Android)
Embarcadero Technologies
65
Mobile Tutorial: Using a Calendar Component to Pick a Date (iOS and Android)
FMX.DateTimeCtrls.TDateEdit
Embarcadero Technologies
66
Mobile Tutorial: Using Combo Box Components to Pick Items from a List (iOS and Android)
Android (LG-E612)
File > New > Multi-Device Application - Delphi > Blank Application
2. Select the TComboBox component in the Tool Palette, and drop it on the
Form Designer.
To find TComboBox, enter the first few characters ("Com") in the Search
box of the Tool Palette:
Embarcadero Technologies
67
Mobile Tutorial: Using Combo Box Components to Pick Items from a List (iOS and Android)
3. After you drop the component, you can see the TComboBox component
on the Form Designer.
Right-click the TComboBox component and select Items Editor...:
5. In the Structure View, select ListBoxItem1 (the first item in the list).
6. In the Object Inspector, edit the Text property for ListBoxItem1.
In this example (the fifty states in the USA), enter "Alabama" as the first
item in the list:
Embarcadero Technologies
68
Mobile Tutorial: Using Combo Box Components to Pick Items from a List (iOS and Android)
Embarcadero Technologies
69
Mobile Tutorial: Using Combo Box Components to Pick Items from a List (iOS and Android)
C++Builder:
void __fastcall TForm1::FormCreate(TObject *Sender)
{
ComboBox2->Items->Add("Tiger");
ComboBox2->Items->Add("Cat");
ComboBox2->Items->Add("Penguin");
ComboBox2->Items->Add("Bee");
// Other animals can be listed here
ComboBox2->Items->Add("Elephant");
ComboBox2->Items->Add("Lion");
}
C++Builder:
void __fastcall TForm1::FormCreate(TObject *Sender)
{
// Index of 5th item is "4"
ComboBox1->ItemIndex = 4;
ComboBox2->Items->Add("Tiger");
ComboBox2->Items->Add("Cat");
ComboBox2->Items->Add("Penguin");
ComboBox2->Items->Add("Bee");
// Other animals can be listed here
ComboBox2->Items->Add("Elephant");
ComboBox2->Items->Add("Lion");
}
Embarcadero Technologies
70
Mobile Tutorial: Using Combo Box Components to Pick Items from a List (iOS and Android)
If you do not know the index value, you can find the value by using the IndexOf
method. To display the ComboBox2 with the item whose text is 'Penguin'
selected, add the following line to the previous code:
Delphi:
ComboBox2.ItemIndex := ComboBox2.Items.IndexOf('Penguin');
C++Builder:
ComboBox2->ItemIndex = ComboBox2->Items->IndexOf("Penguin");
Embarcadero Technologies
71
Mobile Tutorial: Using Combo Box Components to Pick Items from a List (iOS and Android)
C++Builder:
void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
Memo1->Lines->Insert(0, ComboBox1->Name + ": Item " + ComboBox1->Selected>Text + " at Index " + IntToStr(ComboBox1->ItemIndex) + " was selected.");
}
This event handler displays a message dialog that indicates the item that was
selected.
In the Delphi code, the Format function returns a formatted string assembled
from a format string and an array of arguments:
Android (LG - E612)
Embarcadero Technologies
iOS6 (iPad)
72
Mobile Tutorial: Using Combo Box Components to Pick Items from a List (iOS and Android)
See Also
o
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
Embarcadero Technologies
73
Mobile Tutorial: Using a Map Component to Work with Maps (iOS and Android)
This tutorial describes how to create a simple FireMonkey application that uses
the TMapView component.
iOS
Android
iPad
Android (LG - E612)
Embarcadero Technologies
74
Mobile Tutorial: Using a Map Component to Work with Maps (iOS and Android)
Four Types of Maps: Normal, Satellite, Hybrid, and (for Android only) Terrain
Control the Map View: Ability to control the map properties, such as the
map center coordinates, the map orientation, and so on
For Delphi: File > New > Multi-Device Application - Delphi > Blank
Application
For C++: File > New > Multi-Device Application - C++Builder > Blank
Application
2. Select two TToolBar components in the Tool Palette, and drop them on the
Form Designer.
Embarcadero Technologies
75
Mobile Tutorial: Using a Map Component to Work with Maps (iOS and Android)
3. Select the TMapView component in the Tool Palette, and drop it on the
Form Designer.
4. In the Object Inspector, set the Align property of TMapView to Client.
5. In the Object Inspector, set the Align properties of the toolbars to Top and
Bottom, respectively.
In the Tool Palette, select the following components and drop them onto
the top toolbar:
3. In the Tool Palette, select three TSpeedButton components, and add them
as child elements of Layout1.
Embarcadero Technologies
76
Mobile Tutorial: Using a Map Component to Work with Maps (iOS and Android)
After performing the above steps, your Form Designer will be similar to the
following screen:
Embarcadero Technologies
77
Mobile Tutorial: Using a Map Component to Work with Maps (iOS and Android)
2. In the Code Editor, specify the following event handlers for each button:
Delphi:
//-------------------For Normal button ---------------------------------------procedure TForm1.SpeedButton1Click(Sender:TObject) ;
begin
MapView1.MapType := TMapType.Normal;
TrackBar1.Value := 0.0;
end;
// -------------------For Satellite button-------------------------------------procedure TForm1.SpeedButton2Click(Sender:TObject) ;
begin
MapView1.MapType := TMapType.Satellite;
TrackBar1.Value := 0.0;
end;
// --------------------For Hybrid button---------------------------------------procedure TForm1.SpeedButton3Click(Sender:TObject) ;
begin
MapView1.MapType := TMapType.Hybrid;
TrackBar1.Value := 0.0;
end;
C++Builder:
//-------------------For Normal button ---------------------------------------void __fastcall TForm1::SpeedButton1Click(TObject *Sender) {
MapView1->MapType = TMapType::Normal;
TrackBar1->Value = 0.0;
}
// -------------------For Satellite button-------------------------------------void __fastcall TForm1::SpeedButton2Click(TObject *Sender) {
MapView1->MapType = TMapType::Satellite;
TrackBar1->Value = 0.0;
}
// --------------------For Hybrid button---------------------------------------void __fastcall TForm1::SpeedButton3Click(TObject *Sender) {
MapView1->MapType = TMapType::Hybrid;
TrackBar1->Value = 0.0;
}
Embarcadero Technologies
78
Mobile Tutorial: Using a Map Component to Work with Maps (iOS and Android)
To implement the OnChange event handler for the track bar element
1. On the Form Designer, select TrackBarl1.
2. In the Object Inspector, open the Events tab, and then double-click next
to onChange.
Specify the following code:
Delphi:
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
MapView1.Bearing := TrackBar1.Value;
end;
C++Builder:
void __fastcall TForm1::TrackBar1Change(TObject *Sender)
{
MapView1->Bearing = TrackBar1->Value;
}
C++Builder:
void __fastcall TForm1::Button1Click(TObject *Sender) {
TMapCoordinate mapCenter =
TMapCoordinate::Create(StrToFloat(edLat->Text),
StrToFloat(edLong->Text));
MapView1->Location = mapCenter;
}
Embarcadero Technologies
79
Mobile Tutorial: Using a Map Component to Work with Maps (iOS and Android)
Markers identify locations on the map. If you want to add markers to the map,
you can implement the OnMapClick event handler for the map in the following
way.
To implement the OnMapClick event handler for the map
1. In the Structure View, select MapView1.
2. In the Object Inspector, open the Events tab, and double-click next to
OnMapClick.
3. In the Code Editor, implement the following event handler:
Delphi:
procedure TForm1.MapView1MapClick(const Position: TMapCoordinate);
var
MyMarker: TMapMarkerDescriptor;
begin
MyMarker := TMapMarkerDescriptor.Create(Position, 'MyMarker');
// Make a marker draggable
MyMarker.Draggable := True;
// Make a marker visible
MyMarker.Visible :=True;
MapView1.AddMarker(MyMarker);
end;
C++Builder:
void __fastcall TForm1::MapView1MapClick(const TMapCoordinate &Position)
{
TMapMarkerDescriptor myMarker =
TMapMarkerDescriptor::Create(Position, "MyMarker");
// Make a marker draggable
myMarker.Draggable = true;
// Make a marker visible
myMarker.Visible = true;
MapView1->AddMarker(myMarker);
}
Embarcadero Technologies
80
Mobile Tutorial: Using a Map Component to Work with Maps (iOS and Android)
In the left text box, set the latitude value (such as 50 degrees).
In the right text box, set the longitude value (such as 20 degrees).
Android
iPad
See Also
o
TMapView
Embarcadero Technologies
81
Mobile Tutorial: Using a Map Component to Work with Maps (iOS and Android)
Code Samples
o
Map Sample
Embarcadero Technologies
82
Embarcadero Technologies
83
certificate's SHA-1 fingerprint. The fingerprint is the sequence of 20 twodigit hexadecimal numbers separated by colons.
Embarcadero Technologies
84
Important: To get a valid Maps API key, ensure that you use
the exact application's package name. This name uniquely
identifies your application. The package key in the Android
Version Information contains the package name (see the
screenshot under the "To set the apiKey key value"
procedure later in this document).
6. The Google APIs Console displays Key for Android apps (with certificates)
followed by a forty-character API key, for example: API key:
AIzaSyCMuJ2w8_gQEedvqUg-9lxWXFg7feAl9PQ
Embarcadero Technologies
85
Embarcadero Technologies
86
Embarcadero Technologies
87
See Also
o
TMapView
Mobile Tutorial: Using a Map Component to Work with Maps (iOS and
Android)
Code Samples
o
Map Sample
Embarcadero Technologies
88
Mobile Tutorial: Using a MultiView Component to Display Alternate Views of Information (iOS and
Android)
The master pane can display a collection of any visual controls, such as
edit boxes, labels, lists, and so forth.
Embarcadero Technologies
89
Mobile Tutorial: Using a MultiView Component to Display Alternate Views of Information (iOS and
Android)
Drawer
Drawer (Push/Overlap)
Panel
Docked panel
PlatformBehaviour
Popover
Popup menu
NavigationPane
Navigation pane
Custom
Embarcadero Technologies
90
Mobile Tutorial: Using a MultiView Component to Display Alternate Views of Information (iOS and
Android)
Drawer Mode
If you set the TMultiView.Mode property to Drawer (using
TDrawerAppearance.Mode=OverlapDetailView), the master pane is initially
hidden. To display the master pane, the user swipes right from the left edge of
the screen, as shown in the following animated image:
Embarcadero Technologies
91
Mobile Tutorial: Using a MultiView Component to Display Alternate Views of Information (iOS and
Android)
Popover Mode
You can also set the TMultiView.Mode property to Popover to make the master
pane a popup menu that is displayed next to the Master button specified in the
TMultiView.MasterButton property.
Embarcadero Technologies
92
Mobile Tutorial: Using a MultiView Component to Display Alternate Views of Information (iOS and
Android)
Embarcadero Technologies
93
Mobile Tutorial: Using a MultiView Component to Display Alternate Views of Information (iOS and
Android)
Embarcadero Technologies
94
Mobile Tutorial: Using a MultiView Component to Display Alternate Views of Information (iOS and
Android)
Device Orientation
Phone
Tablet
Landscape
Docked panel
Tablet
Portrait
Drawer (push/overlap)
Custom Mode
In Custom mode, you can customize the master pane presentation to conform
to your tasks. To customize the master pane presentation, perform the following
basic steps:
1. Declare your own class, such as MyPresentationClass that descends from
TMultiViewPresentation or from other classes that were declared in the
FMX.MultiView.Presentations unit.
2. In the MyPresentationClass, optionally, override the following virtual
methods defined in the base class:
DoOpen
DoClose
GetDisplayName
DoInstall
DoUninstall
These methods define the master pane behavior.
3. In the Form Designer, select the TMultiView component, and then in the
Object Inspector, set its property Mode to Custom.
4. Implement the onFormCreate event handler as follows:
For Delphi:
Embarcadero Technologies
95
Mobile Tutorial: Using a MultiView Component to Display Alternate Views of Information (iOS and
Android)
For C++:
This topic helps you develop a simple application that illustrates the use of the
TMultiView component.
For Delphi: File > New > Multi-Device Application - Delphi > Blank
Application
For C++: File > New > Multi-Device Application - C++Builder > Blank
Application
2. Select the TMultiView component in the Tool Palette, and drop it on the
Form Designer.
3. Drop other controls, such as buttons, edit boxes or any other controls you
need onto the MultiView container.
4. In the Tool Palette, select a component you want to use as a detail pane
(such as TPanel), and drop any controls onto this panel.
5. In the Object Inspector, specify the appropriate properties of the
TMultiView component.
To clarify this procedure, the following sections consider a particular example: an
application that controls the mobile device camera.
3. Drop a TLabel component into the TMultiview container, and then in the
Object Inspector, set its Text property to Camera type:.
Embarcadero Technologies
96
Mobile Tutorial: Using a MultiView Component to Display Alternate Views of Information (iOS and
Android)
4. Drop two TButton components into the TMultiview container, and then in
the Object Inspector specify the following properties of those buttons:
Name = imgCameraView
Align = Client
Tip: Put all elements of the details pane into a unique container (a
TPanel component in our example). This container should be
specified in the TMultiView.TargetControl property.
Embarcadero Technologies
97
Mobile Tutorial: Using a MultiView Component to Display Alternate Views of Information (iOS and
Android)
For Delphi:
For C++:
2. Double-click the Stop Camera button, and insert the following code:
For Delphi:
For C++:
Embarcadero Technologies
98
Mobile Tutorial: Using a MultiView Component to Display Alternate Views of Information (iOS and
Android)
For Delphi:
For C++:
For Delphi:
For C++:
Embarcadero Technologies
99
Mobile Tutorial: Using a MultiView Component to Display Alternate Views of Information (iOS and
Android)
For Delphi:
For C++:
For the TForm1 class, you should implement the private method GetImage. The
onSampleBufferReady event handler calls this method to get the image from the
device camera.
Do the following:
1. In the private section of the TForm1 class, declare the GetImage method:
For Delphi:
private
{ Private declarations }
procedure GetImage;
For C++:
private:
// User declarations
void __fastcall GetImage();
Embarcadero Technologies
100
Mobile Tutorial: Using a MultiView Component to Display Alternate Views of Information (iOS and
Android)
For Delphi:
procedure TForm1.GetImage;
begin
CameraComponent1.SampleBufferToBitmap(imgCameraView.Bitmap, True);
end;
For C++:
TargetControl = Panel1
Mode = Drawer
Visible = True
Expand the ShadowOptions node, and set the Color property to Beige.
(This property defines the color of the master panel shadow. You can use
any available color.)
Embarcadero Technologies
101
Mobile Tutorial: Using a MultiView Component to Display Alternate Views of Information (iOS and
Android)
5. Optionally, you can select the front or back camera (if available) by using
the Front or Back button, respectively.
MultiViewDemo
LocationDemo
MusicPlayer
See Also
o
FMX.MultiView.TMultiView
FMX.MultiView.TMultiViewPresentation
Embarcadero Technologies
102
Mobile Tutorial: Using the Web Browser Component (iOS and Android)
Embarcadero Technologies
103
Mobile Tutorial: Using the Web Browser Component (iOS and Android)
File > New > Multi-Device Application - Delphi > Blank Application
2. Select the TToolBar component in the Tool Palette, and drop it on the
Form Designer.
To find TToolBar, enter a few characters (such as "tool") in the Search box of the
Tool Palette:
3. After you drop the component, you can see the TToolBar component at
the top of the Form Designer. Here is a screenshot after setting the iOS
style in the Form Designer:
4. Select the TButton component in the Tool Palette and drop it on the
TToolBar.
Embarcadero Technologies
104
Mobile Tutorial: Using the Web Browser Component (iOS and Android)
5. Select the TButton component on the Form Designer, and then in the
Object Inspector, set the StyleLookup property to priortoolbutton.
6. Select the TEdit component in the Tool Palette and drop it on the TToolBar.
Make sure that the size of the Edit control is wide enough to fill the area of
the TToolBar:
7. Select the Edit box on the Form Designer, and then in the Object
Inspector, set the ReturnKeyType property to Done, the KeyboardType
property to URL, and the KillFocusByReturn property to True.
For more information about selecting the most appropriate Virtual Keyboard
type in mobile platforms, see Selecting the Proper Virtual Keyboard for the Web
Browser Application.
8. Select the TWebBrowser component in the Tool Palette and drop it on the
form.
9. Select the Web Browser component on the Form Designer, go to the
Object Inspector and select Client for the Align property.
Embarcadero Technologies
105
Mobile Tutorial: Using the Web Browser Component (iOS and Android)
After you complete these steps, the form should be similar to the following
picture:
Android
iPad
Android (LG - E612
Embarcadero Technologies
106
Mobile Tutorial: Using the Web Browser Component (iOS and Android)
FireMonkey provides many types of event handlers to cover most actions taken
by users. After the "Done" button is selected, the FireMonkey framework sends an
OnChange event to the TEdit control. On the other hand, there is no specific
event for the "Back" button. In this section, you implement event handlers to
support both scenarios.
C++Builder:
private:
// User declarations
void __fastcall openURL();
C++Builder:
void __fastcall TForm1::openURL()
{
WebBrowser1->Navigate(Edit1->Text);
}
Embarcadero Technologies
107
Mobile Tutorial: Using the Web Browser Component (iOS and Android)
C++Builder:
void __fastcall TForm1::Edit1Change(TObject *Sender)
{
openURL();
}
C++Builder:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
WebBrowser1->GoBack();
}
Embarcadero Technologies
108
Mobile Tutorial: Using the Web Browser Component (iOS and Android)
The basic behavior is now implemented for this Web Browser application. Try
running your application on your Android device, the iOS Simulator, or your iOS
device.
Default:
EmailAddress:
NumberPad:
NumbersAndPunctuation: PhonePad:
NamePhonePad:
URL:
Default:
EmailAddress:
NumberPad:
NumbersAndPunctuation: PhonePad:
NamePhonePad:
URL:
The most appropriate Virtual Keyboard type for Web Browser components is URL.
Embarcadero Technologies
109
Mobile Tutorial: Using the Web Browser Component (iOS and Android)
As we have already discussed in Design the User Interface, the following steps set
the URL as the Virtual Keyboard type for the Web Browser component in this
example. Select the Edit box on the Form Designer, and then in the Object
Inspector, set the KeyboardType property to URL.
Subversion
Repository:http://sourceforge.net/p/radstudiodemos/code/HEAD/tree/br
anches/RadStudio_Seattle/Object%20Pascal/Mobile%20Snippets/WebBro
wser
See Also
o
Mobile Tutorial: Using Combo Box Components to Pick Items from a List
(iOS and Android)
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
FMX.KeyboardTypes Sample
Embarcadero Technologies
110
Mobile Tutorial: Using the Web Browser Component (iOS and Android)
TWebBrowser
TToolBar
TButton
TEdit
KeyboardType
StyleLookup
Embarcadero Technologies
111
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
On Android:
Tabs are commonly placed at the top of the screen (so you should
set TTabPosition either to Top or to PlatformDefault).
On iOS:
Tabs are typically shown at the bottom of the screen (so you should
set TTabPosition either to Bottom or to PlatformDefault).
Tab items always display both text and an icon, which can be set
via the StyleLookup property for each tab.
Embarcadero Technologies
112
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
For Delphi: File > New > Multi-Device Application - Delphi > Blank
Application
For C++: File > New > Multi-Device Application - C++Builder > Blank
Application
Embarcadero Technologies
113
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
3. After you drop the TTabControl, an empty TabControl is shown on the Form
Designer (you might need to manually adjust the position of the
TabControl):
4. Typically, applications that use TabControl use the full screen to show
pages.
To do this, you need to change the default alignment of TabControl. In
the Object Inspector, change the Align property of TabControl to Client:
Embarcadero Technologies
114
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
5. Right-click the TabControl, and select Items Editor... from the context
menu:
6. Click Add Item three times, so that now you have three instances of
TabItem here. Close the dialog box.
Embarcadero Technologies
115
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
7. On the Form Designer, select the first TabItem and change its StyleLookup
property:
iOS
Android
Embarcadero Technologies
116
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
:
9. To change the location of tabs, select the TabPosition property for the
TabControl component, and set it to one of the following values in the
Object Inspector:
Embarcadero Technologies
117
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
Android
Embarcadero Technologies
118
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
Bottom
iOS
Android
Embarcadero Technologies
119
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
Dots
iOS
Android
Embarcadero Technologies
120
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
None
iOS
Android
No Tabs or Dots are displayed at run time, although you can see them at design time.
Page can be changed only through code or action.
Embarcadero Technologies
121
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
Platform Default
iOS
Android
Embarcadero Technologies
122
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
Notes:
o
In Android apps, predefined icons are not supported, so you must use
custom icons.
In iOS apps, you can use either predefined icons or custom icons.
To use custom icons on either iOS or Android, select the appropriate iOS or
Android Style in the Form Designer, set the StyleLookup property of
TTabItem to tabitemcustom, specify your custom icon as described in this
section, and then build your app.
For iOS, you can use our predefined icons by setting the StyleLookup
property of TTabItem to the icon of your choice, such as
(tabitemsearch).
The custom glyphs used in this section are available in a zip file that is
delivered in your C:\Program Files
(x86)\Embarcadero\Studio\17.0\Images\GlyFX directory.
The three PNGs used here are located in the Icons\Aero\PNG\32x32
directory:
users_32 (People)
unlock_32 (Security)
tree_32 (Organization)
Unzip the glyFX.zip file before you use the MultiResBitmap Editor if you want to
use these images or any others available in the GlyFX collection.
Embarcadero Technologies
123
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
2. Select a tab, and click the ellipsis button [...] on the CustomIcon property
of TTabItem in the Object Inspector:
Embarcadero Technologies
124
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
4. Ensure that you are in the Master view, and in the MultiResBitmap Editor,
click the array next to Custom size, and then choose Default size.
5. Repeat the following steps to add any additional scales that you want to
support:
1. In the MultiResBitmap Editor, click
Embarcadero Technologies
When you have added all the scales you want, the editor
looks like this:
125
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
The selected image now appears appropriately scaled in each of the Scale
entries on the MultiResBitmap Editor:
Embarcadero Technologies
126
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
To specify a single-resolution bitmap for a custom icon, perform the first step of
the procedure above and then proceed as follows:
1. In the Structure View, select Empty under CustomIcon:
2. Now, in the Object Inspector, click the ellipsis button [...] in the Bitmap field
(of the TabItem1.CustomIcon[0]). This opens the Bitmap Editor:
Embarcadero Technologies
127
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
3. In the Bitmap Editor, click the Load... button, and select a PNG file.
The recommended size is 30x30 pixels for normal resolution, and 60x60
pixels for high resolution:
Embarcadero Technologies
128
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
Embarcadero Technologies
129
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
Android
Embarcadero Technologies
130
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
Actions respond when a control fires, for example, when the application
user clicks a button or chooses a menu item.
Here are the steps to enable a user to move to different tab pages by clicking a
button:
1. On the Form Designer, click TabItem1 to select it.
2. From the Tool Palette, add a TActionList component to the form, and then
add a TButton to TabItem1:
Embarcadero Technologies
131
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
3. With the button selected, in the Object Inspector, select Action | New
Standard Action | Tab > TChangeTabAction from the drop-down menu.
After the user clicks this button, the action you just defined is performed
(the tab page changes):
Embarcadero Technologies
132
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
Embarcadero Technologies
133
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
5. With the previous step, the caption (the Text property) of the button is
automatically changed to "Go To Security" because the caption of
TabItem2 is "Security" in our example. Set the CustomText property of the
ChangeTabAction1 component to Security as shown below and change
the size of the button to fit the new caption text, if required.
7. On the Form Designer, select TabItem2 and drop two TButtons from the
Tool Palette to TabItem2.
Embarcadero Technologies
134
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
8. On the Form Designer, select Button2 and in the Object Inspector, select
Action | New Standard Action | Tab > TPreviousTabAction from the dropdown menu.
9. On the Form Designer, select Button3 and in the Object Inspector, select
Action | New Standard Action | Tab > TNextTabAction from the dropdown menu.
10. Select PreviousTabAction1 in the Structure View and in the Object
Inspector, set its TabControl property to TabControl1.
11. Select NextTabAction1 in the Structure View and in the Object Inspector,
set its TabControl property to TabControl1.
12. On the Form Designer, select TabItem3 and drop a TButton from the Tool
Palette to TabItem3.
13. In the Object Inspector, set the Action property of the button to
PreviousTabAction1.
Embarcadero Technologies
135
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
By Source Code
You can use any of the following three ways to change the active tab page
from your source code, by clicking the button.
C++:
TabControl1->ActiveTab = TabItem1;
Embarcadero Technologies
136
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
C++:
TabControl1->TabIndex = 2;
Embarcadero Technologies
137
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
C++:
// You can set the target at run time if it is not defined yet.
ChangeTabAction1->Tab = TabItem2;
// Call the action
ChangeTabAction1->ExecuteTarget(NULL);
See Also
o
Mobile Tutorial: Using a Button Component with Different Styles (iOS and
Android)
Mobile Tutorial: Using the Web Browser Component (iOS and Android)
Embarcadero Technologies
138
Embarcadero Technologies
139
2. In the Tool Palette, locate a TListView component and drop it onto the
form.
3. Add a TPrototypeBindSource component to the form.
4. On the form, select the ListView1 component, and then in the Object
Inspector, set the Align property to Client and the SearchVisible property
to True.
The form should now look like the following screen, before you set the Style or
View in the Form Designer:
Note: For more information about the selection of the Style and Views, see Style
Selector and Using FireMonkey Views.
Embarcadero Technologies
140
2. From the Add Field dialog box, select ColorsNames and click OK.
Embarcadero Technologies
141
Embarcadero Technologies
142
3. Optionally, you can apply a tint to the TListView text buttons. Do the
following:
In the Object Inspector, locate the TintColor property and set its
value to an appropriate value, such as Seagreen.
Embarcadero Technologies
143
The following image shows both the Structure View and the Object Inspector. In
the Structure View, Item is expanded and TextButton is selected, and in the
Object Inspector, TintColor is set to Seagreen:
Note: At design time, the tint color that you applied to text buttons
might not be visible. To make your changes visible, choose the
Master view in the Style selector to change the current style of your
Form Designer to either Android or iOS. For details, see Form
Designer.
At this point in the tutorial, you have configured the ListView component to
display an image on the left-hand side of the item text, and to display a button
on the right-hand side of the item text.
In the next step, you populate the image and the button with sample data.
Embarcadero Technologies
144
Now the list view displays some color data associated with each item and also
displays sample currency data on the button associated with each list item.
Embarcadero Technologies
145
C++Builder:
void __fastcall TForm1::ListView1ButtonClick(TObject * const Sender,
TListViewItem * const AItem, TListItemSimpleControl * const AObject) {
ShowMessage(AItem->Text + " " + AItem->ButtonText + " is clicked.");
}
Embarcadero Technologies
146
The Results
To see your mobile app as it would appear on a mobile device, you need to
configure your system as described in the appropriate Setup tutorial, available
here, and set the View to a target mobile device (such as iPhone 4") in the Form
Designer. Then you need to complete the necessary steps for deploying your
app to the target mobile platform.
Then you can run the application on your mobile device, either by pressing F9 or
by choosing Run > Run.
iOS
iPad
Embarcadero Technologies
Android
Galaxy S4
147
If you click the Blue item, the application displays the following message box:
See Also
o
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
FMX.ListView.TListView
TPrototypeBindSource
LiveBindings Designer
Embarcadero Technologies
148
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)
Plain List
iOS
Embarcadero Technologies
149
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)
Grouped List
Embarcadero Technologies
150
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)
Search Box
You can add a search box to a ListBox. With a search box, users can easily
narrow down a selection from a long list as in the following pictures.
This tutorial describes the basic steps to build items for a Table View in your multidevice applications for mobile platforms.
For Delphi: File > New > Multi-Device Application - Delphi > Blank
Application
Embarcadero Technologies
151
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)
2. Select the TListBox component in the Tool Palette, and drop it on the Form
Designer. To find TListBox, enter a few characters (such as "TList") in the
Search box of the Tool Palette:
Embarcadero Technologies
152
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)
5. On the Items Designer, click the Add Item button several times to add
several items to the ListBox:
6. Close the Items Designer. Now you can find your ListBox Items on the
TListBox component. For example:
Embarcadero Technologies
153
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)
Add a Header
You can define a Header on the TListBox component by using the following
steps:
2. On the Tool Palette, select the TLabel component and drop it on top of
the TListBoxHeader component you just added:
Embarcadero Technologies
154
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)
Value
Align
Client
StyleLookup
toollabel
TextSettings.HorzAlign
Text
Center
(Text value as you want)
3. Select TListBoxGroupFooter from the drop-down list, and then select Add
Item.
Embarcadero Technologies
155
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)
5. Close the dialog box. Now you have a Group Header and a Group Footer
on the TListBox component.
transparentlistboxstyle = StyleLookup
Property Value
You can select the GroupingKind property and the StyleLookup property in the
Object Inspector when the ListBox is selected in the Form Designer.
Embarcadero Technologies
156
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)
You can select the Accessory property in the Object Inspector when ListBox Item
is selected in the Form Designer.
You can select the Bitmap property in the Object Inspector when the ListBoxItem
is selected in the Form Designer.
In order to view the Icon, you must select a StyleLookup which supports the
Bitmap property. Change the StyleLookup property to listboxitemleftdetail.
Embarcadero Technologies
157
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)
listboxitemnodetail
listboxitembottomdetail
listboxitemrightdetail
listboxitemleftdetail
For Delphi: File > New > Multi-Device Application - Delphi > Blank
Application
2. Select the TListBox component in the Tool Palette, and drop it on the Form
Designer.
3. Select the TListBox component on the Form Designer, go to the Object
Inspector and select Client for the Align property.
Embarcadero Technologies
158
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)
Delphi:
ListBox1.Items.Add('Text to add');
C++:
ListBox1->Items->Add("Text to add");
If you want to create items other than a simple item, or control other properties,
you can create an instance of the item first, and then add it to the list box.
The following sample codes add items to a ListBox, as shown in the picture:
iOS
Embarcadero Technologies
159
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)
Delphi:
procedure TForm1.FormCreate(Sender: TObject);
var
c: Char;
i: Integer;
Buffer: String;
ListBoxItem : TListBoxItem;
ListBoxGroupHeader : TListBoxGroupHeader;
begin
ListBox1.BeginUpdate;
for c := 'a' to 'z' do
begin
// Add header ('A' to 'Z') to the List
ListBoxGroupHeader := TListBoxGroupHeader.Create(ListBox1);
ListBoxGroupHeader.Text := UpperCase(c);
ListBox1.AddObject(ListBoxGroupHeader);
// Add items ('a', 'aa', 'aaa', 'b', 'bb', 'bbb', 'c', ...) to the list
for i := 1 to 3 do
begin
// StringOfChar returns a string with a specified number of repeating
characters.
Buffer := StringOfChar(c, i);
// Simply add item
// ListBox1.Items.Add(Buffer);
// or, you can add items by creating an instance of TListBoxItem by
yourself
ListBoxItem := TListBoxItem.Create(ListBox1);
ListBoxItem.Text := Buffer;
// (aNone=0, aMore=1, aDetail=2, aCheckmark=3)
ListBoxItem.ItemData.Accessory := TListBoxItemData.TAccessory(i);
ListBox1.AddObject(ListBoxItem);
end;
end;
ListBox1.EndUpdate;
end;
Embarcadero Technologies
160
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)
C++:
void __fastcall TForm1::FormCreate(TObject *Sender)
{
char c;
int i;
String Buffer ;
TListBoxItem *ListBoxItem ;
TListBoxGroupHeader *ListBoxGroupHeader
ListBox1->BeginUpdate();
for (c = 'a'; c <= 'z'; c++)
{
// Add header ('A' to 'Z') to the List
ListBoxGroupHeader = new TListBoxGroupHeader(ListBox1);
ListBoxGroupHeader->Text = UpperCase(c);
ListBox1->AddObject(ListBoxGroupHeader);
// Add items ('a', 'aa', 'aaa', 'b', 'bb', 'bbb', 'c', ->->->) to the
list
for (i = 1; i < 4; i++)
{
// StringOfChar returns a string with a specified number of repeating
characters->
Buffer = StringOfChar(c, i);
// Simply add item
// ListBox1->Items->Add(Buffer);
// or, you can add items by creating an instance of TListBoxItem by
yourself
ListBoxItem = new TListBoxItem(ListBox1);
ListBoxItem->Text = Buffer;
// (aNone=0, aMore=1, aDetail=2, aCheckmark=3)
ListBoxItem->ItemData->Accessory =
static_cast<TListBoxItemData::TAccessory>(i);
ListBox1->AddObject(ListBoxItem);
};
};
ListBox1->EndUpdate();
}
Embarcadero Technologies
161
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)
Check akTop and akRight from the Anchors property of the TListBox
component.
Embarcadero Technologies
162
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)
Change the Text property to the text value that you want.
Embarcadero Technologies
Android LG-E612
163
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)
Delphi:
C++:
Embarcadero Technologies
164
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)
Delphi:
procedure TForm1.SearchButtonClick(Sender: TObject);
begin
SearchBox1.Visible := not SearchBox1.Visible; //change the visibility status
end;
C++:
void __fastcall TForm1::SearchButtonClick(TObject *Sender) {
SearchBox1->Visible = !(SearchBox1->Visible); //change the visibility
status
}
Embarcadero Technologies
165
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)
2. To invoke the overflow menu, click the vertical ellipsis on the Action bar.
3. To view the search box, click the SearchButton.
Android (Samsung Tab 2.0)
Embarcadero Technologies
166
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)
See Also
o
FMX.ListBox.TListBox
Mobile Tutorial: Using a Button Component with Different Styles (iOS and
Android)
Mobile Tutorial: Using the Web Browser Component (iOS and Android)
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
Embarcadero Technologies
167
Mobile Tutorial: Using LiveBindings to Populate a ListBox in Mobile Applications (iOS and Android)
2. Select the TListBox component in the Tool Palette, and drop it on the Form
Designer.
3. Select the list box component on the Form Designer, and in the Object
Inspector, locate the DefaultItemStyles.ItemStyle property. Set it to the
listboxitemrightdetail style.
4. Unselect the list box component by clicking in a blank area of the Form
Designer.
5. Select the TRectangle component in the Tool Palette, and drop it on the
Form Designer.
6. Select the rectangle component on the Form Designer, and in the Object
Inspector, set the Align property to Bottom.
7. Select the list box component and set its Align property to Client.
8. Now drop a TPrototypeBindSource from the Tool Palette onto your form.
Embarcadero Technologies
168
Mobile Tutorial: Using LiveBindings to Populate a ListBox in Mobile Applications (iOS and Android)
At this point, your form should be similar to the following iOS screen:
Embarcadero Technologies
169
Mobile Tutorial: Using LiveBindings to Populate a ListBox in Mobile Applications (iOS and Android)
You need to add sample data for colors and color names to the
TPrototypeBindSource component in order to support the purpose of this tutorial
and to link to the list box and the rectangle.
1. Right-click the TPrototypeBindSource component, and then click Add
Field on the context menu.
2. Select AlphaColors and ColorsNames from the Field Data list, and clear
the Shuffle Values check box.
This operation adds sample alphabetically sorted data (alpha color
values and names).
3. Validate your selection by clicking the OK button. Now the sample data is
ready to be used through LiveBindings.
Embarcadero Technologies
170
Mobile Tutorial: Using LiveBindings to Populate a ListBox in Mobile Applications (iOS and Android)
Embarcadero Technologies
171
Mobile Tutorial: Using LiveBindings to Populate a ListBox in Mobile Applications (iOS and Android)
Embarcadero Technologies
172
Mobile Tutorial: Using LiveBindings to Populate a ListBox in Mobile Applications (iOS and Android)
The Results
To run the application, press F9 or choose Run > Run.
When you select a list box item, the rectangle's color changes accordingly:
iOS (iPad)
Embarcadero Technologies
Android (LG-E612)
173
Mobile Tutorial: Using LiveBindings to Populate a ListBox in Mobile Applications (iOS and Android)
See Also
o
LiveBindings Designer
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
Embarcadero Technologies
174
Mobile Tutorial: Using Layout to Adjust Different Form Sizes or Orientations (iOS and Android)
Embarcadero Technologies
175
Mobile Tutorial: Using Layout to Adjust Different Form Sizes or Orientations (iOS and Android)
The default value for the Align property is None, which means that no automatic
calculations are performed: the control stays where it is placed:
Align = None
Typical values for the Align property are as follows (Dodgerblue indicates the
area for the child):
Top
Bottom
Left
Right
Center
Client
If you use an Align value of Top, Bottom, Left, or Right for one component, the
Align properties for other components use the remaining area.
The size and shape of the remaining area (Client) also changes based on the
orientation of the device, and based on the form factor (iPhone or iPad).
Embarcadero Technologies
176
Mobile Tutorial: Using Layout to Adjust Different Form Sizes or Orientations (iOS and Android)
The following pictures show the layout for landscape (horizontal) and for portrait
(vertical) when you have two (2) components that use Top, and one (1)
component that uses Client.
Left
Right
Bottom
Top
Embarcadero Technologies
177
Mobile Tutorial: Using Layout to Adjust Different Form Sizes or Orientations (iOS and Android)
In the following picture, the parent component (which contains two regions)
uses the Padding property to ensure space inside the parent component:
Android
Embarcadero Technologies
178
Mobile Tutorial: Using Layout to Adjust Different Form Sizes or Orientations (iOS and Android)
Android:
You can use Align, Padding, Margins, Anchors, and other properties of TLayout to
define the layout for a specific area. You can use the TLayout component just
like the DIV tag in HTML.
Embarcadero Technologies
179
Mobile Tutorial: Using Layout to Adjust Different Form Sizes or Orientations (iOS and Android)
See Also
o
Gestures in FireMonkey
Embarcadero Technologies
180
Mobile Tutorial: Taking and Sharing a Picture, and Sharing Text (iOS and Android)
Mobile Tutorial: Using a Button Component with Different Styles (iOS and
Android)
This tutorial covers the following typical tasks for using pictures and sharing text
with your applications in mobile platforms.
On iOS Devices:
Taking a picture with the device camera
Embarcadero Technologies
181
Mobile Tutorial: Taking and Sharing a Picture, and Sharing Text (iOS and Android)
Sharing text
On Android Devices:
Taking a picture with the device camera Using a picture from the device Photo Library
Embarcadero Technologies
182
Mobile Tutorial: Taking and Sharing a Picture, and Sharing Text (iOS and Android)
Embarcadero Technologies
Sharing text
183
Mobile Tutorial: Taking and Sharing a Picture, and Sharing Text (iOS and Android)
Topics
o
See Also
o
FireMonkey Actions
FMX.StdCtrls.TButton
FMX.Objects.TImage
FMX.MediaLibrary
FMX.PhotoEditorDemo Sample
FMX.CameraComponent Sample
http://appleinsider.com/articles/12/02/16/share_sheets
Embarcadero Technologies
184
Mobile Tutorial: Using the Web Browser Component (iOS and Android)
Embarcadero Technologies
185
In the TListBox, set the Align property to Left to reserve the left side of the
UI. Then create the following subcomponents under the ListBox:
Embarcadero Technologies
186
After you create these components, select all TListBoxItem items and select
listboxitemleftdetail in the StyleLookup property. This allows TListBoxItem to show
both a label and detailed text.
Tip: You should specify the lowest accuracy that works for your application; the
higher the accuracy, the more time and power that the sensor requires to
determine the location. The recommended values: Distance=0; Accuracy=0.
Embarcadero Technologies
187
C++:
void __fastcall TForm1::Switch1Switch(TObject *Sender)
{
LocationSensor1->Active = Switch1->IsChecked;
}
Embarcadero Technologies
188
C++:
void __fastcall TForm1::LocationSensor1LocationChanged(TObject *Sender, const
TLocationCoord2D &OldLocation,
const TLocationCoord2D &NewLocation)
{
char LDecSeparator = FormatSettings.DecimalSeparator;
FormatSettings.DecimalSeparator = '.';
// Show current location
ListBoxItemLatitude->ItemData->Detail = ListBoxItemLatitude->ItemData>Detail.sprintf(L"%2.6f", NewLocation.Latitude);
ListBoxItemLongitude->ItemData->Detail = ListBoxItemLongitude>ItemData->Detail.sprintf(L"%2.6f", NewLocation.Longitude);
}
Embarcadero Technologies
189
So you can add this URL to your previously created event handler
OnLocationChanged as follows:
Delphi:
procedure TForm1.LocationSensor1LocationChanged(Sender: TObject;
const OldLocation, NewLocation: TLocationCoord2D);
var
URLString: String;
begin
// code for previous step goes here
// Show Map using Google Maps
URLString := Format(
'https://maps.google.com/maps?q=%s,%s',
[Format('%2.6f', [NewLocation.Latitude]), Format('%2.6f',
[NewLocation.Longitude])]);
WebBrowser1.Navigate(URLString);
end;
C++:
void __fastcall TForm1::LocationSensor1LocationChanged(TObject *Sender, const
TLocationCoord2D &OldLocation,
const TLocationCoord2D &NewLocation)
{
// code for previous step goes here
// Show Map using Google Maps
String LLongitude = FloatToStr(NewLocation.Longitude, FormatSettings);
String URLString = "";
URLString =
URLString.sprintf(L"https://maps.google.com/maps?q=%2.6f,%2.6f",
NewLocation.Latitude, NewLocation.Longitude);
FormatSettings.DecimalSeparator = LDecSeparator;
WebBrowser1->Navigate(URLString);
}
Embarcadero Technologies
190
Embarcadero Technologies
191
C++:
Note: Place this code snippet in the header file (.h)
class TForm1 : public TForm
{
// IDE defines visible (or non-visual) components here automatically
private:
// User declarations
TGeocoder *FGeocoder;
void __fastcall OnGeocodeReverseEvent(TCivicAddress* const Address);
public:
// User declarations
__fastcall TForm1(TComponent* Owner);
};
Now you can create an instance of TGeocoder and set it up with data with the
following Delphi or C++ code.
TGeocoder.Current gives the type of class that actually implements the
Geocoding Service. The code in "TGeocoder.Current.Create" calls the
constructor (Create) for the specified type, and saves it to the FGeocoder field.
You also need to specify an event handler, which is fired when TGeocoder
completes Reverse Geocoding. Assign OnGeocodeReverseEvent (which you just
defined in the previous step) to FGeocoder.OnGeocodeReverse.
Finally, if you successfully created an instance of TGeocoder, and TGeocoder is
not running, call TGeocoder.GeocodeReverse with location information. After
TGeocoder receives data, the OnGeocodeReverseEvent event is fired.
Delphi:
procedure TForm1.LocationSensor1LocationChanged(Sender: TObject;
const OldLocation, NewLocation: TLocationCoord2D);
begin
// code for previous steps goes here
try
// Setup an instance of TGeocoder
if not Assigned(FGeocoder) then
begin
if Assigned(TGeocoder.Current) then
FGeocoder := TGeocoder.Current.Create;
if Assigned(FGeocoder) then
FGeocoder.OnGeocodeReverse := OnGeocodeReverseEvent;
end;
// Translate location to address
if Assigned(FGeocoder) and not FGeocoder.Geocoding then
FGeocoder.GeocodeReverse(NewLocation);
except
ListBoxGroupHeader1.Text := 'Geocoder service error';
end;
end;
Embarcadero Technologies
192
C++:
void __fastcall TForm1::LocationSensor1LocationChanged(TObject *Sender, const
TLocationCoord2D &OldLocation,
const TLocationCoord2D &NewLocation)
{
// code for previous steps goes here
// Setup an instance of TGeocoder
try {
if (FGeocoder == NULL) {
if (TGeocoder::Current != NULL) {
FGeocoder = (TGeocoder*)new TGeocoderClass(TGeocoder::Current);
}
if (FGeocoder != NULL) {
FGeocoder->OnGeocodeReverse = OnGeocodeReverseEvent;
}
}
// Translate location to address
if ((FGeocoder != NULL) && (FGeocoder->Geocoding)) {
FGeocoder->GeocodeReverse(NewLocation);
}
}
catch (...) {
ListBoxGroupHeader1->Text = "Geocoder service error";
}
}
Embarcadero Technologies
193
Address: TCivicAddress);
:=
:=
:=
:=
:=
:=
:=
:=
:=
:=
Address.AdminArea;
Address.CountryCode;
Address.CountryName;
Address.FeatureName;
Address.Locality;
Address.PostalCode;
Address.SubAdminArea;
Address.SubLocality;
Address.SubThoroughfare;
Address.Thoroughfare;
C++:
void __fastcall TForm1::OnGeocodeReverseEvent(TCivicAddress*
{
if (Address != NULL){
ListBoxItemAdminArea->ItemData->Detail
>AdminArea;
ListBoxItemCountryCode->ItemData->Detail
>CountryCode;
ListBoxItemCountryName->ItemData->Detail
>CountryName;
ListBoxItemFeatureName->ItemData->Detail
>FeatureName;
ListBoxItemLocality->ItemData->Detail
>Locality;
ListBoxItemPostalCode->ItemData->Detail
>PostalCode;
ListBoxItemSubAdminArea->ItemData->Detail
>SubAdminArea;
ListBoxItemSubLocality->ItemData->Detail
>SubLocality;
ListBoxItemSubThoroughfare->ItemData->Detail
>SubThoroughfare;
ListBoxItemThoroughfare->ItemData->Detail
>Thoroughfare;
}
}
Embarcadero Technologies
const Address)
= Address= Address= Address= Address= Address= Address= Address= Address= Address= Address-
194
See Also
o
System.Sensors.TGeocoder
System.Sensors.Components.TLocationSensor
Embarcadero Technologies
195
Android
Embarcadero Technologies
196
iPad
Android Notification Number
Android
Embarcadero Technologies
197
Android
For Delphi applications, add the following 2 units to the uses clause
if they are not present:
uses
FMX.Platform, FMX.Notification;
#include <FMX.Platform.hpp>
#include <FMX.Notification.hpp>
Embarcadero Technologies
198
Embarcadero Technologies
199
4. Implement the event handler for the OnClick event of the SetNumber
button by adding the following code:
For Delphi:
For C++:
Embarcadero Technologies
200
After running your application (press F9) and clicking the SetNumber button, you
can see the following:
o
Android
Schedule Notification
You can also schedule Notification Messages using the ScheduleNotification
method that the TNotificationCenter class inherits from
TCustomNotificationCenter.
To show a Notification Message, you need to create an instance of the
TNotification class, and then define the Name, AlertBody, and FireDate fields.
1. Drop a new TButton to the form.
2. In the Object Inspector, change the Name property to
ScheduleNotification.
3. Create the OnClick event of the ScheduleNotification button by doubleclicking the button.
Embarcadero Technologies
201
For Delphi:
For C++:
Embarcadero Technologies
202
After running your application (press F9) and clicking the ScheduleNotification
button, you can see the Notification Message (AlertBody) at the top of your
device Home Screen. For iOS devices, this message is similar to the following
screen:
For Delphi:
Embarcadero Technologies
203
For C++:
After running your application (press F9) and clicking the RepeatedNotification
button, you can see the Notification Message (AlertBody) at the top of your
device Home Screen. For iOS devices, this message is similar to the following
screen:
204
For Delphi:
For C++:
Embarcadero Technologies
205
For Delphi:
Embarcadero Technologies
206
For C++:
Embarcadero Technologies
207
For Delphi:
For C++:
Embarcadero Technologies
208
For Delphi:
uses
System.IOUtils;
private
function GetSoundName: string;
For C++:
#include <System.IOUtils.hpp>
private:
// User declarations
__fastcall UnicodeString GetSoundName ();
For Delphi:
{$R *.fmx}
function TForm1.GetSoundName: string;
begin
{$IFDEF IOS}
Result := 'myiOSSound.caf';
{$ENDIF}
{$IFDEF ANDROID}
Result := TPath.Combine(TPath.GetSharedDocumentsPath,
'myAndroidSound.mp3');
{$ENDIF}
end;
Embarcadero Technologies
209
For C++:
In the Confirm dialog, click Yes to add the sound files to your
project.
8. Open the Deployment Manager to ensure that the sound files are
deployed with your application. You can see the corresponding entries in
the remote path column:
9. Change the remote path of the added files in the Deployment Manager:
For iOS: .\
Embarcadero Technologies
210
Android
o
Embarcadero Technologies
211
To use a notification alert instead of a notification banner (only for iOS devices),
the end user needs to change the Alert style to Alerts through the configuration
page of Notification Center, available in the device Settings:
Embarcadero Technologies
212
For Delphi:
For C++:
Embarcadero Technologies
213
The notification alert opens at the time that was specified through the FireDate
field.
For Delphi:
For C++:
Embarcadero Technologies
214
See Also
o
Mobile Tutorial: Taking and Sharing a Picture, and Sharing Text (iOS and
Android)
FMX.Notification.IFMXNotificationCenter
SendCancelNotifications
Embarcadero Technologies
215
Protocols:
Parse
Kinvey
Backend service:
EMS
In order to receive push notifications, you need to set up the messaging service
(APS or GCM), the device, the cloud service provider or EMS, and your RAD
Studio application, as described in the three pages of this mobile tutorial.
Notes:
o
iOS and Android also have local notifications which are sent from an app
or from the OS to get the users attention. For more information, see
Mobile Tutorial: Using Notifications (iOS and Android).
The term Service Provider covers in this tutorial the Cloud service providers
(Kinvey and Parse) and the backend service provider EMS.
Embarcadero Technologies
216
See Also
o
BaaS Overview
Mobile Tutorial: Using BaaS for Backend Storage (iOS and Android)
Code Samples
o
Embarcadero Technologies
217
Kinvey
Parse
EMS
Embarcadero Technologies
218
Embarcadero Technologies
219
Embarcadero Technologies
220
Note: You do not need to add the GCM AppID when developing Android apps
and using Parse.
Embarcadero Technologies
221
Embarcadero Technologies
222
Embarcadero Technologies
223
Embarcadero Technologies
224
C++:
//------------------------------------------------------------------------void __fastcall TForm1::PushEvents1DeviceRegistered(TObject *Sender)
{
Memo1->Lines->Add("Device Registered");
Memo1->Lines->Add("");
}
//------------------------------------------------------------------------void __fastcall TForm1::PushEvents1DeviceTokenReceived(TObject *Sender)
{
Memo1->Lines->Add("Device Token Received");
Memo1->Lines->Add("");
}
//------------------------------------------------------------------------void __fastcall TForm1::PushEvents1DeviceTokenRequestFailed(TObject
*Sender, const UnicodeString AErrorMessage)
{
Memo1->Lines->Add("Device Token Request Failed");
Memo1->Lines->Add(AErrorMessage);
Memo1->Lines->Add("");
}
//------------------------------------------------------------------------void __fastcall TForm1::PushEvents1PushReceived(TObject *Sender,
TPushData * const AData)
{
Memo1->Lines->Add("Push Received");
Memo1->Lines->Add(AData->Message);
Memo1->Lines->Add("");
}
//-------------------------------------------------------------------------
Embarcadero Technologies
225
Android Settings
Note: To verify whether your Android device supports GCM, see GCM Overview
Project Settings
To enable your application to receive remote notifications:
1. Right-click your project in the Project Manager.
2. Choose Project > Options > Entitlement List.
3. Set Receive Push Notification value to True.
Note: If you want to enable receiving a notification even if the application is not
running while the remote notification comes in, you will need to register a Service
Class. This Java service class will create an entry in the Notification Center of the
Android Device. If you do not need or want items in the Notification Center, you
can skip this step.
You need to include an additional entry in the AndroidManifest.xml for the
project, by customizing your AndroidManifest.template.xml. In the
AndroidManifest.template.xml file of your project search for the following tag:
<%receivers%>
Embarcadero Technologies
226
iOS Settings
Project Settings
1. Right-click your project in the Project Manager.
2. Choose Project > Options > Version Info, and set the CFBundleIdentifier
key. This should be the same as the identifier of your App ID. It is the
Bundle ID from Creating iOS App ID on Apple Developer Program section.
Embarcadero Technologies
227
4. Go to Parse, Kinvey or Sending EMS Push Messages and send a new push:
Note: You can use your own EMS application to send EMS Push Notifications
messages.
Parse
Kinvey
Embarcadero Technologies
228
EMS
Android
Embarcadero Technologies
229
iOS EMS
6. Send your app to background and send another push from Parse or
Kinvey. Now go to Notifications:
iOS
Android
Embarcadero Technologies
230
See Also
o
Mobile Tutorial: Using BaaS for Backend Storage (iOS and Android)
Entitlement List
Code Samples
o
Embarcadero Technologies
231
Mobile Tutorial: Using the Phone Dialer on Mobile Devices (iOS and Android)
Make a call
Add the following lines to your code if they are not present:
Delphi:
uses
FMX.Platform, FMX.PhoneDialer;
C++:
#include <FMX.Platform.hpp>
#include <FMX.PhoneDialer.hpp>
Embarcadero Technologies
232
Mobile Tutorial: Using the Phone Dialer on Mobile Devices (iOS and Android)
Only for Delphi apps: Add the following line to the public section of the
form definition:
Add the following properties to the private section of the form definition:
Delphi:
private: // User declarations
PhoneDialerService: IFMXPhoneDialerService;
C++:
private: //User declarations
_di_IFMXPhoneDialerService phoneDialerService;
bool serviceSupported;
Only for Delphi apps: in the implementation section, override the form
constructor as follows:
Only for C++Builder apps: in the Structure View, click the form, and in the
Object Inspector, open the Events tab, and then double-click onCreate.
Implement the following onCreate event handler for the application form:
Embarcadero Technologies
233
Mobile Tutorial: Using the Phone Dialer on Mobile Devices (iOS and Android)
Name to btnGetCarrierInfo
Embarcadero Technologies
234
Mobile Tutorial: Using the Phone Dialer on Mobile Devices (iOS and Android)
C++:
void __fastcall TForm1::btnGetCarrierInfoClick(TObject *Sender)
{
if (serviceSupported) {
lblCarrierName->Text = "Carrier Name: " + phoneDialerService>GetCarrier()->GetCarrierName();
lblISOCountryCode->Text = "ISO Country Code: " +
phoneDialerService->GetCarrier()->GetIsoCountryCode();
}
else ShowMessage("This device does not support the Phone Dialer
services.");
}
Call phone
Embarcadero Technologies
235
Mobile Tutorial: Using the Phone Dialer on Mobile Devices (iOS and Android)
After you click the Get Carrier Info button, the application displays the basic
information about the carrier, similar to the following screens:
iOS
Android
Making a Call
FireMonkey provides the IFMXPhoneDialerService.Call method that makes a
phone call to a specified phone number.
For your application to make calls, add the following elements to the Form
Designer:
1. Add a TLabel component, and then set its Text property to Telephone
Number.
Embarcadero Technologies
236
Mobile Tutorial: Using the Phone Dialer on Mobile Devices (iOS and Android)
2. Add a TEdit component, and in the Object Inspector, set the following
properties:
Name to edtTelephoneNumber.
KillFocusByReturn to True.
KeyboardType to PhonePad.
ReturnKeyType to Go.
On the Events tab, double-click onClick, and then implement the onClick
event handler as follows:
Delphi:
procedure TForm1.btnMakeCallClick(Sender: TObject);
begin
{ test whether the PhoneDialer services are supported on your device }
if Assigned(PhoneDialerService) then
begin
{ if the Telephone Number is entered in the edit box then make the call,
else
display an error message }
if edtTelephoneNumber.Text <> '' then
PhoneDialerService.Call(edtTelephoneNumber.Text)
else
begin
ShowMessage('Please type-in a telephone number.');
edtTelephoneNumber.SetFocus;
end;
end;
end;
C++:
void __fastcall TForm1::btnMakeCallClick(TObject *Sender)
{
if (serviceSupported) {
if (edtTelephoneNumber->Text != "" )
{
phoneDialerService->Call(edtTelephoneNumber->Text);
}
else {
ShowMessage("Please type-in a telephone number.");
edtTelephoneNumber->SetFocus();
}
}
else ShowMessage("This device does not support the Phone Dialer
services.");
}
Embarcadero Technologies
237
Mobile Tutorial: Using the Phone Dialer on Mobile Devices (iOS and Android)
To make a call:
1. Run the application.
2. In the TEdit field under Telephone Number, type the phone number.
3. Click the Make Call button.
iOS
Embarcadero Technologies
Android
238
Mobile Tutorial: Using the Phone Dialer on Mobile Devices (iOS and Android)
Description
iOS Android
None
No call state.
Connected
Incoming
Dialing
C++:
void __fastcall MyOnCallStateChanged(const UnicodeString aCallID, const
TCallState aCallState);
Embarcadero Technologies
239
Mobile Tutorial: Using the Phone Dialer on Mobile Devices (iOS and Android)
C++:
void __fastcall TForm1::FormCreate(TObject *Sender)
{
serviceSupported = (TPlatformServices::Current>SupportsPlatformService(__uuidof(IFMXPhoneDialerService)) &&
(phoneDialerService = TPlatformServices::Current>GetPlatformService(__uuidof(IFMXPhoneDialerService))));
if (serviceSupported) {
phoneDialerService->OnCallStateChanged = MyOnCallStateChanged;
}
}
Embarcadero Technologies
240
Mobile Tutorial: Using the Phone Dialer on Mobile Devices (iOS and Android)
C++:
void __fastcall TForm1::MyOnCallStateChanged(const UnicodeString aCallID,
const TCallState aCallState) {
switch (aCallState) {
case TCallState::None:
lblCallState->Text = "No calls";
break;
case TCallState::Connected:
lblCallState->Text = "Connected";
break;
case TCallState::Incoming:
lblCallState->Text = "Incoming call";
break;
case TCallState::Dialing:
lblCallState->Text = "Dialing";
break;
case TCallState::Disconnected:
lblCallState->Text = "Disconnected";
break;
}
}
After you implement this event handler, the application shows the phone call
state.
Embarcadero Technologies
241
Mobile Tutorial: Using the Phone Dialer on Mobile Devices (iOS and Android)
For example, the following iOS screen indicates that the phone is in a dialing
state:
Note: In this sample project, the TLabel component is next to the TEdit box and
the Make Call button, under Telephone Number.
Embarcadero Technologies
242
Mobile Tutorial: Using the Phone Dialer on Mobile Devices (iOS and Android)
See Also
o
Mobile Tutorial: Taking and Sharing a Picture, and Sharing Text (iOS and
Android)
FMX.PhoneDialer.IFMXPhoneDialerService
Embarcadero Technologies
243
Mobile Tutorial: Using BaaS for Backend Storage (iOS and Android)
iPod
Android
Nexus 7
With backend storage you can store files and data in the cloud. This information
can later be retrieved, updated, and deleted.
In this tutorial you are going to:
o
Embarcadero Technologies
244
Mobile Tutorial: Using BaaS for Backend Storage (iOS and Android)
For Delphi: File > New > Multi-Device Application - Delphi > Blank
Application
For C++: File > New > Multi-Device Application - C++Builder > Blank
Application
2. Drop a TLabel on the form and set the following properties in the Object
Inspector:
3. Drop a TButton on the TLabel and set the following properties in the
Object Inspector:
4. Drop a TEdit on the form and set the following properties in the Object
Inspector:
Embarcadero Technologies
245
Mobile Tutorial: Using BaaS for Backend Storage (iOS and Android)
5. Drop a TButton on the TEdit and set the following properties in the Object
Inspector:
6. Drop a TListView on the form and set the following properties in the Object
Inspector:
Embarcadero Technologies
246
Mobile Tutorial: Using BaaS for Backend Storage (iOS and Android)
Embarcadero Technologies
247
Mobile Tutorial: Using BaaS for Backend Storage (iOS and Android)
C++:
void __fastcall TForm1::AddItemButtonClick(TObject *Sender)
{
TJSONObject *LJSONObject;
TBackendEntityValue LEntity;
if (Edit1->Text == "") {
ShowMessage("Please, enter an item.");
}
else {
LJSONObject = new TJSONObject;
LJSONObject->AddPair("item", Edit1->Text);
BackendStorage1->Storage->CreateObject("ShoppingList",
LJSONObject, LEntity);
ShowMessage("New item created: "+ Edit1->Text);
LJSONObject->Free();
delete LJSONObject;
Edit1->Text="";
}
}
Embarcadero Technologies
248
Mobile Tutorial: Using BaaS for Backend Storage (iOS and Android)
Deleting Objects
To allow users to delete any item from the list. In the TListView component, if you
swipe your finger left or right over one of the items of the TListView, a Delete
button displays on the right-hand side. To delete the item when the Delete
button of such item is clicked, do the following:
1. Select the TListView and in the Events tab of the Object Inspector, doubleclick the OnDeletingItem event. This event occurs before the item is
deleted. Add the following code:
Delphi:
procedure TForm1.ListView1DeletingItem(Sender: TObject; AIndex: Integer; var
ACanDelete: Boolean);
var
LQuery: string;
LJSONArray : TJSONArray;
LEntities: TArray<TBackendEntityValue>;
begin
ACanDelete := False;
LJSONArray := TJSONArray.Create;
try
LQuery := Format('query={"item":"%s"}', [(Sender as
TListView).Items[AIndex].Text]); // 'query={"item":"%s"}' in Kinvey and
'where={"item":"%s"}' in Parse
BackendStorage1.Storage.QueryObjects('ShoppingList', [LQuery], LJSONArray,
LEntities);
if (Length(LEntities) > 0) and
BackendStorage1.Storage.DeleteObject('ShoppingList', LEntities[0].ObjectID)
then
ACanDelete := True
else
ShowMessage ('Item could not be deleted.');
finally
LJSONArray.Free;
end;
end;
Embarcadero Technologies
249
Mobile Tutorial: Using BaaS for Backend Storage (iOS and Android)
C++:
void __fastcall TForm1::ListView1DeletingItem(TObject *Sender, int AIndex, bool
&ACanDelete)
{
System::UnicodeString LQuery[1];
DynamicArray<TBackendEntityValue> LEntities;
ACanDelete = False;
TJSONArray *LJSONArray;
LJSONArray = new TJSONArray;
try {
TListView* list = reinterpret_cast<TListView*>(Sender);
LQuery[0] = ("query={\"item\":\""+(list->Items->Item[AIndex]>Text)+"\"}"); // "query={\"item\":\"" in Kinvey and "where={\"item\":\"" in
Parse
BackendStorage1->Storage->QueryObjects("ShoppingList", LQuery,
0, LJSONArray, LEntities);
if (((LEntities.Length)>0) & BackendStorage1->Storage>DeleteObject("ShoppingList", LEntities[0].ObjectID)) {
ACanDelete = True;
} else {
ShowMessage("Item could not be deleted.");
}
}
__finally {
LJSONArray->Free();
}
}
Note: The line LQuery[0]=("query={\"item\":\""+(list->Items->Item[AIndex]>Text)+"\"}"); is for Kinvey. In Parse, the word query must change to where so if
you are using Parse as BaaS provider, this line must
be LQuery[0]=("where={\"item\":\""+(list->Items->Item[AIndex]->Text)+"\"}");.
Embarcadero Technologies
250
Mobile Tutorial: Using BaaS for Backend Storage (iOS and Android)
Retrieving Objects
To update all content in the TListView to reflect any possible change, you can
retrieve the objects with QueryObjects, clear the list view and add all items you
have retrieved from the backend storage.
1. To add a new method to refresh the list:
Delphi:
Open the Class Explorer window by choosing View > Class Explorer.
In the Class Viewer pane, right-click TForm1 under Unit1 and select
Add Method.
Embarcadero Technologies
251
Mobile Tutorial: Using BaaS for Backend Storage (iOS and Android)
C++:
Open the Class Explorer window by choosing View > C++ Class
Explorer.
In the Type List pane (left pane), expand your project, right-click
TForm1 under and select Add Method.
Embarcadero Technologies
252
Mobile Tutorial: Using BaaS for Backend Storage (iOS and Android)
C++:
void TForm1::RefreshList()
{
String LQuery [1];
TJSONArray *LJSONArray;
TListViewItem *LItem;
TJSONObject *LJSONObject;
String ItemText;
int i;
LJSONArray = new TJSONArray;
try {
BackendStorage1->Storage->QueryObjects("ShoppingList",
LQuery, 0, LJSONArray);
ListView1->ClearItems();
for (i = 0; i < LJSONArray->Count; i++) {
LItem = ListView1->Items->Add();
LJSONObject = dynamic_cast<TJSONObject
*>(LJSONArray->Items[i]);
ItemText = (LJSONObject->Values["item"]>Value());
LItem->Text = ItemText;
}
}
__finally {
LJSONArray->Free();
}
}
3. Double-click the RefreshButton and the following code so this button calls
the RefreshList method:
Delphi:
procedure TForm1.RefreshButtonClick(Sender: TObject);
begin
RefreshList;
end;
C++:
void __fastcall TForm1::RefreshButtonClick(TObject *Sender)
{
RefreshList();
}
Embarcadero Technologies
253
Mobile Tutorial: Using BaaS for Backend Storage (iOS and Android)
C++:
RefreshList();
5. To refresh the list after an item is deleted, select the TListView and in the
Events tab of the Object Inspector, double-click the OnDeleteItem event.
This event occurs after the item is deleted. Add the following code:
Delphi:
procedure TForm1.ListView1DeleteItem(Sender: TObject; AIndex: Integer);
begin
RefreshList;
end;
C++:
void __fastcall TForm1::ListView1DeleteItem(TObject *Sender, int AIndex)
{
RefreshList();
}
Embarcadero Technologies
254
Mobile Tutorial: Using BaaS for Backend Storage (iOS and Android)
3. Once you add or delete items in your application, you can go to your
Kinvey console or to your Parse dashboard to see the changes also from
the cloud.
iOS
iPod
Embarcadero Technologies
Android
Nexus 7
255
Mobile Tutorial: Using BaaS for Backend Storage (iOS and Android)
See Also
o
BaaS Overview
Code Samples
o
Embarcadero Technologies
256
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
Embarcadero Technologies
257
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
This tutorial describes the basic steps to browse data managed by InterBase
ToGo on your iOS and Android devices through the dbExpress framework.
iOS
Android
Note: You can use FireDAC, dbExpress, and Interbase Express (IBX) components
to build Interbase ToGo applications. For a detailed discussion on Interbase
Express components usage in a Delphi application, read the Getting Started with
InterBase Express article. For this tutorial, we will connect to Interbase ToGo using
dbExpress framework.
Embarcadero Technologies
258
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
For other databases, such as Oracle, you need to have at least a client
library. On Windows platforms, the client library is provided as a DLL to
connect to. Therefore, you need to develop applications using middle-tier
technologies such as DataSnap to connect to these database products
from a mobile device.
File > New > Multi-Device Application - Delphi > Blank Application
4. Add a TPanel component to the form, and set the following properties in
the Object Inspector:
5. Add a TLabel component to the Panel, and set the following properties in
the Object Inspector:
Embarcadero Technologies
259
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
Embarcadero Technologies
260
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
Embarcadero Technologies
261
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
3. Open the LiveBindings Designer and connect the data and the user
interface as follows:
1. Click COMMON_NAME in SQLDataSet1, and drag the mouse cursor
to Item.Text in ListView1.
Embarcadero Technologies
262
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
Check the configuration (to connect to the database file) to a local file
under the Documents folder (for iOS device) or internal storage (for
Android device).
Interbase ToGo
1. You can add the database to your project with one of the following two
methods:
the Project Manager. Click Yes to confirm that you want to add the
file to your project.
Embarcadero Technologies
263
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
2. After adding the database file, the Featured Files window displays. Select
the following database modules, and then click OK to close the Featured
Files dialog box:
The suggested names for the license files available are listed
in the Featured Files dialog, under the following name
pattern: reg_*.txt.
As you can see in the image below, the reg_ibtogo.txt license file is selected for
this tutorial.
desired license.
If you have saved the file with its original name, then
select Add Files (shown in the next step) and include
the license file in the list of files that need to be
deployed with the application.
Embarcadero Technologies
264
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
Tip: If you plan to test your application on the iOS Simulator, then you also have
to select the DBExpress InterBase Driver for iOS Simulator.
Embarcadero Technologies
265
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
5. See how the Remote Path of dbdemos.gdb has been set for iOS and
Android platforms:
As you just configured, when you run the app on the mobile device, the
database file (dbdemos.gdb) is to be deployed to the Documents folder (for iOS
platform) or internal storage (for Android platform) in the sandbox area of your
multi-device application.
Embarcadero Technologies
266
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
C++:
void __fastcall TForm1::SQLConnection1BeforeConnect(TObject *Sender)
{
#if defined(_PLAT_IOS) || defined(_PLAT_ANDROID)
SQLConnection1->Params->Values["Database"] =
System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetDocumentsPath(),
"dbdemos.gdb");
#endif
}
Embarcadero Technologies
267
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
Embarcadero Technologies
Android
268
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
Troubleshooting
InterBase Issues
See the following section with detailed information about Interbase License
Issues.
Note: Follow the steps at IBLite and IBToGo Test Deployment Licensing to obtain a
valid license file.
C++:
void __fastcall TForm1::Button1Click(TObject *Sender) {
try {
SQLConnection1->Connected = True;
SQLDataSet1->Active = True;
}
catch(Exception *e) {
ShowMessage(e->Message);
}
Embarcadero Technologies
269
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
See Also
o
http://www.embarcadero.com/products/interbase/product-editions
Embarcadero Technologies
270
Mobile Tutorial: Using InterBase ToGo with FireDAC (iOS and Android)
Embarcadero Technologies
271
Mobile Tutorial: Using InterBase ToGo with FireDAC (iOS and Android)
This tutorial describes the basic steps to browse data managed by InterBase
ToGo on your iOS and Android devices through the FireDAC framework.
iOS
Android
Note: You can use FireDAC, dbExpress, and Interbase Express (IBX) components
to build Interbase ToGo applications. For a detailed discussion on Interbase
Express components usage in a Delphi application, read the Getting Started with
InterBase Express article. For this tutorial, we will connect to Interbase ToGo using
FireDAC.
Embarcadero Technologies
272
Mobile Tutorial: Using InterBase ToGo with FireDAC (iOS and Android)
For other databases, such as Oracle, you need to have at least a client
library. On Windows platforms, the client library is provided as a DLL to
connect to. Therefore, you need to develop applications using middle-tier
technologies such as DataSnap to connect to these database products
from a mobile device.
File > New > Multi-Device Application - Delphi > Blank Application
4. Add a TPanel component to the form, and set the following properties in
the Object Inspector:
Embarcadero Technologies
273
Mobile Tutorial: Using InterBase ToGo with FireDAC (iOS and Android)
5. Add a TLabel component to the Panel, and set the following properties in
the Object Inspector:
Embarcadero Technologies
274
Mobile Tutorial: Using InterBase ToGo with FireDAC (iOS and Android)
Embarcadero Technologies
275
Mobile Tutorial: Using InterBase ToGo with FireDAC (iOS and Android)
Embarcadero Technologies
276
Mobile Tutorial: Using InterBase ToGo with FireDAC (iOS and Android)
8. Open the LiveBindings Designer and connect the data and the user
interface as follows:
1. Click COMMON_NAME in FDQuery1, and drag the mouse cursor to
Item.Text in ListView1.
Embarcadero Technologies
277
Mobile Tutorial: Using InterBase ToGo with FireDAC (iOS and Android)
can only read and write data that is located in the Documents folder (for iOS
device) and internal storage (for Android device) under your application folder.
To connect to a local database on mobile, you need to perform the following
actions:
o
Check the configuration (to connect to the database file) to a local file
under the Documents folder (for iOS device) or internal storage (for
Android device).
Interbase ToGo required file (the license file and other configuration files)
the Project Manager. Click Yes to confirm that you want to add the
file to your project.
Embarcadero Technologies
278
Mobile Tutorial: Using InterBase ToGo with FireDAC (iOS and Android)
2. After adding the database file, the Featured Files window displays. Select
InterBase ToGo in the Feature Files, and then click OK to close the
Featured Files dialog box.
Under the node InterBase ToGo you need to select the license to
be used when deploying the application on the device.
The suggested names for the license files available are listed
in the Featured Files dialog, under the following name
pattern: reg_*.txt.
As you can see in the image below, the reg_ibtogo.txt license file is selected for
this tutorial.
desired license.
Embarcadero Technologies
279
Mobile Tutorial: Using InterBase ToGo with FireDAC (iOS and Android)
If you have saved the file with its original name, then
select Add Files (shown in the next step) and include
the license file in the list of files that need to be
deployed with the application.
Embarcadero Technologies
280
Mobile Tutorial: Using InterBase ToGo with FireDAC (iOS and Android)
5. See how the Remote Path of dbdemos.gdb has been set for iOS and
Android platforms:
As you just configured, when you run the app on the mobile device, the
database file (dbdemos.gdb) is to be deployed to the Documents folder (for iOS
platform) or internal storage (for Android platform) in the sandbox area of your
multi-device application.
For the TFDConnection, create the BeforeConnect event handler as follows:
1. In the Form Designer, select the TFDConnection component.
2. In the Object Inspector, go to the Events tab and double-click the
BeforeConnect event.
Embarcadero Technologies
281
Mobile Tutorial: Using InterBase ToGo with FireDAC (iOS and Android)
3. Implement the event handler for the BeforeConnect event by adding the
following code:
For Delphi:
For C++:
Embarcadero Technologies
282
Mobile Tutorial: Using InterBase ToGo with FireDAC (iOS and Android)
Embarcadero Technologies
Android
283
Mobile Tutorial: Using InterBase ToGo with FireDAC (iOS and Android)
Troubleshooting
InterBase Issues
See the following section with detailed information about Interbase License
Issues.
Note: Follow the steps at IBLite and IBToGo Test Deployment Licensing to obtain a
valid license file.
C++:
void __fastcall TForm1::Button1Click(TObject *Sender) {
try {
FDConnection1->Connected = true;
FDQuery1->Active = true;
}
catch(Exception &e) {
ShowMessage(e.Message);
}
}
284
Mobile Tutorial: Using InterBase ToGo with FireDAC (iOS and Android)
See Also
o
InterBase ToGo
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
http://www.embarcadero.com/products/interbase/product-editions
Embarcadero Technologies
285
This tutorial describes the basic steps to use SQLite as a local data storage on
your mobile device through the dbExpress framework.
iOS
Embarcadero Technologies
Android
286
For other databases, such as Oracle, you need to have at least a client
library. On Windows platforms, the client library is provided as a DLL to
connect to. Therefore, you need to develop applications using middle-tier
technologies such as DataSnap to connect to these database products
from a mobile device.
Embarcadero Technologies
287
4. Click the Advanced button and open the Advanced Properties dialog
box.
5. Change the FailIfMissing property to False and click OK to close the
Advanced Properties dialog box:
Embarcadero Technologies
288
Note: Setting FailIfMissing to False instructs the Data Explorer to create a new
database file if the file is not available.
6. Back on the Modify Connection dialog box, click the Test Connection
button. With this operation, the new database file is created if no file
existed:
Note: Ensure that sqlite3.dll is present on your development system. If this file is
not present, download sqlite3.dll from http://www.sqlite.org/download.html to
your system path (such as C:\Windows\SysWOW64 for 64-bit Windows).
3. Click the Save button and specify a table name (for example, Item.)
Embarcadero Technologies
289
Embarcadero Technologies
290
4. Drop a TButton on the ToolBar component and set the following properties
in the Object Inspector:
5. Drop a TLabel on the ToolBar component and set the following properties
in the Object Inspector:
6. Drop a TListBox component on the form and set the following properties in
the Object Inspector:
Set the Align property to Client, so that the ListBox component uses
the entire form.
Embarcadero Technologies
291
Following these steps connects the user interface of the app with data on a
SQLite database. If you used a table with existing data for this tutorial, now you
should see actual data within the Form Designer.
Embarcadero Technologies
292
Select ListBox1 and define the following event handler for the OnItemClick
event.
Delphi:
procedure TForm1.ListBox1ItemClick(const Sender: TCustomListBox;
const Item: TListBoxItem);
begin
if ListBox1.Selected <> nil then
ButtonDelete.Visible := True
else
ButtonDelete.Visible := False;
end;
C++Builder:
void __fastcall TForm1::ListBox1ItemClick(const TCustomListBox *Sender,const
TListBoxItem *Item)
{
if (ListBox1->Selected)
ButtonDelete->Visible = True;
else
ButtonDelete->Visible = False;
}
Embarcadero Technologies
293
Embarcadero Technologies
294
Declare this procedure prototype under the private section of the Form class:
private
procedure OnInputQuery_Close(const AResult: TModalResult; const AValues:
array of string);
Embarcadero Technologies
295
C++Builder:
To replicate the same functionality in C++, additional steps are required:
1. Add the next type definition after the TForm1 definition:
typedef void __fastcall (__closure *TInputCloseQueryProcEvent)(const
System::Uitypes::TModalResult AResult,
System::UnicodeString const *AValues, const int AValues_High);
3. Add the next declaration under the private section of the form:
void __fastcall OnInputQuery_Close(const System::Uitypes::TModalResult AResult,
System::UnicodeString const *AValues, const int AValues_High);
Embarcadero Technologies
296
Embarcadero Technologies
297
The InputQuery function shows a dialog box asking the end user to enter a text.
This function returns True when the user selects OK, so that you can add data to
the database only when the user selects OK and the text contains some data.
iOS
Android
Embarcadero Technologies
298
C++Builder:
void __fastcall TForm1::ButtonDeleteClick(TObject *Sender) {
String TaskName = ListBox1->Selected->Text;
try {
SQLQueryDelete->ParamByName("ShopItem")->AsString = TaskName;
SQLQueryDelete->ExecSQL();
ItemTable->Refresh();
LinkFillControlToField1->BindList->FillList();
if (ListBox1->Selected)
ButtonDelete->Visible = True;
else
ButtonDelete->Visible = False;
}
catch (Exception &e) {
ShowMessage(e.Message);
}
}
Embarcadero Technologies
299
Check the configuration (to connect to the database file) to a local file
under the Documents folder (for iOS device) or internal storage (for
Android device).
in the Project Manager. Click Yes to confirm that you want to add
the file to your project.
2. After adding the database file, the Featured Files window displays, click
Cancel to close it.
3. Open the Deployment Manager by selecting Project > Deployment.
4. Select Debug configuration - iOS Device - 32 bit platform, Debug
configuration - iOS Device - 64 bit platform or Debug configuration Android platform from the drop-down list of target platforms at the top of
the Deployment Manager and see that the database shoplist.s3db has
been added to the platforms.
Embarcadero Technologies
300
5. See how the Remote Path of shoplist.s3db has been set for iOS and
Android platforms:
As you just configured, when you run the app on the mobile device, the
database file (shoplist.s3db) is set to be deployed to the Documents folder (for
iOS platform) or internal storage (for Android platform) in the sandbox area of
your multi-device application.
Embarcadero Technologies
301
C++Builder:
void __fastcall TForm1::ShoppinglistConnectionBeforeConnect(TObject *Sender) {
#if defined(_PLAT_IOS) || defined(_PLAT_ANDROID)
ShoppinglistConnection->Params->Values["ColumnMetadataSupported"] =
"False";
ShoppinglistConnection->Params->Values["Database"] =
System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetDocumentsPath(),
"shoplist.s3db");
#endif
}
C++Builder:
void __fastcall TForm1::ShoppinglistConnectionAfterConnect(TObject *Sender){
ShoppinglistConnection->ExecuteDirect("CREATE TABLE IF NOT EXISTS Item
(ShopItem TEXT NOT NULL)");
}
Embarcadero Technologies
302
Embarcadero Technologies
303
iOS
Android
Note: If you have an issue with running the application, follow the steps given in
Troubleshooting.
Embarcadero Technologies
304
See Also
o
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
Embarcadero Technologies
305
This tutorial describes the basic steps to use SQLite as a local data storage on
your mobile device through the FireDAC framework.
iOS
Embarcadero Technologies
Android
306
For other databases, such as Oracle, you need to have at least a client
library. On Windows platforms, the client library is provided as a DLL to
connect to. Therefore, you need to develop applications using middle-tier
technologies such as DataSnap REST to connect to these database
products from a mobile device.
For Delphi: File > New > Multi-Device Application - Delphi > Blank
Application
For C++: File > New > Multi-Device Application - C++Builder > Blank
Application
Embarcadero Technologies
307
C:\Users\Public\Documents\Embarcadero\Studio\17.0\Samples\Data\shoplist
.s3db (location of the database)
Embarcadero Technologies
308
Embarcadero Technologies
309
To set up a ListView component and other UI elements, use the following steps:
1. Drop a TToolBar on the form.
2. Drop a TButton on the ToolBar component and set the following properties
in the Object Inspector:
3. Drop a TButton on the ToolBar component and set the following properties
in the Object Inspector:
4. Drop a TLabel on the ToolBar component and set the following properties
in the Object Inspector:
5. Drop a TListView component on the form and set the following properties
in the Object Inspector:
Embarcadero Technologies
310
Embarcadero Technologies
311
Embarcadero Technologies
312
Embarcadero Technologies
313
Embarcadero Technologies
314
Following these steps connects the user interface of the app with data on a
SQLite database. If you used a table with existing data for this tutorial, now you
should see actual data within the Form Designer.
Select ListView1 and define the following event handler for the
OnItemClick event.
Delphi:
procedure TForm1.ListView1ItemClick(const Sender: TObject;
const AItem: TListViewItem);
begin
ButtonDelete.Visible := ListView1.Selected <> nil;
end;
For C++:
Embarcadero Technologies
315
Embarcadero Technologies
316
For Delphi:
private
procedure OnInputQuery_Close(const AResult: TModalResult; const AValues:
array of string);
Embarcadero Technologies
317
For C++:
Add the following definition after the TForm1 definition (in the .h file of your
unit):
Add the following class definition (in the .h file of your unit, after the
previously defined type):
Add the following declaration under the private section of the form (in the
.h file of your unit):
Embarcadero Technologies
318
Add the following code (in the .cpp file of your unit):
Embarcadero Technologies
319
The InputQuery function shows a dialog box asking the end user to enter text. This
function returns True when the user selects OK, so that you can add data to the
database only when the user selects OK and the text contains some data.
iOS
Android
Embarcadero Technologies
320
For Delphi:
For C++:
Embarcadero Technologies
321
Check the configuration (to connect to the database file) to a local file
under the Documents folder (for iOS device) or internal storage (for
Android device).
in the Project Manager. Click Yes to confirm that you want to add
the file to your project.
Embarcadero Technologies
322
2. After adding the database file, the Featured Files window displays, click
Cancel to close it.
3. Open the Deployment Manager by selecting Project > Deployment.
4. Select Debug configuration - iOS Device - 32 bit platform, Debug
configuration - iOS Device - 64 bit platform or Debug configuration Android platform from the drop-down list of target platforms at the top of
the Deployment Manager and see that the database shoplist.s3db has
been added to the platforms.
5. See how the Remote Path of shoplist.s3db has been set for iOS and
Android platforms:
As you just configured, when you run the app on the mobile device, the
database file (shoplist.s3db) is set to be deployed to the Documents folder (for
iOS platform) or internal storage (for Android platform) in the sandbox area of
your multi-device application.
Embarcadero Technologies
323
For Delphi:
For C++:
Embarcadero Technologies
324
For Delphi:
TEXT NOT
For C++:
TEXT NOT
Embarcadero Technologies
325
Android
Note: If you have an issue with running the application, follow the
steps given in Troubleshooting.
See Also
o
Mobile Tutorial: Using InterBase ToGo with FireDAC (iOS and Android)
Embarcadero Technologies
326
Mobile Tutorial: Connecting to an Enterprise Database from a Mobile Client (iOS and Android)
Embarcadero Technologies
327
Mobile Tutorial: Connecting to an Enterprise Database from a Mobile Client (iOS and Android)
Embarcadero Technologies
328
Mobile Tutorial: Connecting to an Enterprise Database from a Mobile Client (iOS and Android)
Embarcadero Technologies
329
Mobile Tutorial: Connecting to an Enterprise Database from a Mobile Client (iOS and Android)
Embarcadero Technologies
330
Mobile Tutorial: Connecting to an Enterprise Database from a Mobile Client (iOS and Android)
Embarcadero Technologies
331
Mobile Tutorial: Connecting to an Enterprise Database from a Mobile Client (iOS and Android)
Embarcadero Technologies
332
Mobile Tutorial: Connecting to an Enterprise Database from a Mobile Client (iOS and Android)
With this event handler, the DataSnap Server exposes providers as well as public
methods in this class to a DataSnap client. Based on the steps in the previous
section, now you are going to expose the DataSetProvider_EMPLOYEE
DataSetProvider component to your DataSnap client.
.
Now you can see the DataSnap server running on your Windows machine.
Because this DataSnap server has no UI element, it looks like a blank form, and
this is as expected at this point.
Embarcadero Technologies
333
Mobile Tutorial: Connecting to an Enterprise Database from a Mobile Client (iOS and Android)
Embarcadero Technologies
334
Mobile Tutorial: Connecting to an Enterprise Database from a Mobile Client (iOS and Android)
If you see an error, please double-check the properties you have just set.
TListBox component
Embarcadero Technologies
335
Mobile Tutorial: Connecting to an Enterprise Database from a Mobile Client (iOS and Android)
7. Open the LiveBindings Designer and connect the data and user interface
as follows:
1. Click FULL_NAME in BindSourceDB1, and drag the mouse cursor to
Item.Text in ListBox1:
iOS
Embarcadero Technologies
Android
336
Mobile Tutorial: Connecting to an Enterprise Database from a Mobile Client (iOS and Android)
MIDAS Library
):
3. Select the following module, and then click OK to close the Deployment
Manager:
MIDAS Library
Embarcadero Technologies
337
Mobile Tutorial: Connecting to an Enterprise Database from a Mobile Client (iOS and Android)
See Also
o
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
Datasnap.DSServer.TDSServer
Embarcadero Technologies
338
Android
Embarcadero Technologies
339
The FireDAC native driver supports SQLite database version 3.0 and later. For a
detailed discussion on SQLite usage in FireDAC for a Delphi application, read the
"Using SQLite with FireDAC" article.
To use SQLite in your application, the sqlite3.dll file must be present on your
development system. If this file is not present, download sqlite3.dll from
http://www.sqlite.org/download.html to your system path (such as
C:\Windows\SysWOW64 for 64-bit Windows).
Embarcadero Technologies
340
Embarcadero Technologies
341
Embarcadero Technologies
342
Embarcadero Technologies
343
Embarcadero Technologies
344
LiveBindings Designer
Use the LiveBindings Designer to add new connections between the
TBindSourceDB and TListView components.
1. Select the ItemHeader.Text member from TListView.
2. Bind to the Department member of the BindSourceDB1 component by
dragging (a connection line appears).
3. Select the Item.Text member from TListView.
4. Bind to the Name member of the BindSourceDB1 component by dragging
(a connection line appears).
5. In the Object Inspector, set the following properties of TListView:
1. Set the ItemAppearance to ImageListItemRightButton.
In the LiveBindings Designer, the TListView should have a new member,
Item.ButtonText.
2. Set the Align property to Client.
6. In the LiveBindings Designer, select the Item.ButtonText member from
TListView.
7. Bind to the Seniority member of the BindSourceDB1 component by
dragging (a connection line appears).
Embarcadero Technologies
345
Change the configuration (to connect to the database file) to a local file
under the Documents folder (for iOS device) or internal storage (for
Android device).
Embarcadero Technologies
346
4. Select the Platforms column (double-click the ellipsis [...] in the row for
Employees.s3db):
1. Ensure that iOSSimulator, iOSDevice32 and iOSDevice64 or Android
are present for Employees.s3db.
2. Remove Win32 from the list if it is present (you do not have to copy
database files to the Win32 platform).
5. Select All-Configurations - iOS Device - 32 bit platform, All-Configurations iOS Device - 64 bit platform or All-Configurations - Android platform and
make sure Employees.s3db is set to be deployed to StartUp\Documents\
or assets\internal\.
As you just configured, when you run the app on the mobile device, the
database file (Employees.s3db) is set to be deployed to the Documents folder
(for iOS platform) or internal storage (for Android platform) in the sandbox area
of your application.
Embarcadero Technologies
347
Embarcadero Technologies
348
Android
See Also
o
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
Embarcadero Technologies
349
Mobile Tutorial
Creating a Multi-Device
Application (iOS and Android)
TButton, TSpeedButton
TDateEdit
TComboBox
TMultiView, TDrawerAppearance
Embarcadero Technologies
350
Using LiveBindings to
Populate a ListBox in TListBox, DefaultItemStyles.ItemStyle, TRectangle,
Mobile Applications TPrototypeBindSource, LiveBindings Designer,
(iOS and Android)
Using Layout to
Adjust Different Form TLayout and its properties: Align, Margins, Padding, and Anchors
Sizes or Orientations TVertScrollBox
(iOS and Android)
Taking and Sharing a
Picture, and Sharing
Text (iOS and
Android)
Using Location
Sensors (iOS and
Android)
Using Notifications
(iOS and Android)
Connecting to an
Enterprise Database
from a Mobile Client
(iOS and Android)
Using Remote
TPushEvents, AutoActivate, TKinveyProvider, AppKey, AppSecret,
Notifications (iOS and MasterSecret, TParseProvider, ApplicationID, RestApiKey,Provider,
Android)
LiveBindings Designer
Using BaaS for
Backend Storage
(iOS and Android)
Embarcadero Technologies
351
Note: This list of components is intended for informational purposes only, and
might not be entirely accurate or complete.
Embarcadero Technologies
352