Mobile Tutorials en PDF
Mobile Tutorials en PDF
Mobile Tutorials en PDF
April, 2016
Embarcadero Technologies 2
CONTENTS
Mobile Tutorials: Mobile Application Development (iOS and Android) ................. 12
Setup ................................................................................................................................. 12
Using Basic User Interface Elements ............................................................................. 13
Using Device Functionality ............................................................................................ 15
Using Backend as a Service .......................................................................................... 16
Accessing a Database .................................................................................................. 17
See Also......................................................................................................................... 17
Mobile Tutorial: Set Up Your Development Environment on the Mac (iOS) .......... 18
Requirements on the Mac and iOS .......................................................................... 18
Steps to Configure Your Mac to Run Your iOS Application .................................. 19
Step 1: Install the Platform Assistant ...................................................................... 19
Step 2: Run the Platform Assistant ......................................................................... 20
Step 3: Install Xcode on the Mac .......................................................................... 21
Next Steps ................................................................................................................. 22
Additional Steps to Configure Your Mac to Run Your iOS Application on Your iOS
Device............................................................................................................................... 22
Step 1: Make Sure that the Xcode Command Line Tools Are Installed on Your
Mac ............................................................................................................................... 23
Step 2: Sign Up for a Developer Account ............................................................... 24
Step 3: Request, Download and Install Your Development Certificate ............. 24
Request, Download and Install Your Certificate ................................................ 25
Step 4: Register Your Device for Deployment......................................................... 26
Step 5: Create and Install a Provisioning Profile ..................................................... 27
See Also......................................................................................................................... 28
Mobile Tutorial: Set Up Your Development Environment on Windows PC (iOS) ... 29
Setting Up Your RAD Studio Environment ................................................................ 30
Create a Connection Profile for the Mac ........................................................... 30
Add an SDK to the Development System for the iOS Device Connected to
the Mac..................................................................................................................... 33
See Also......................................................................................................................... 35
Mobile Tutorial: Set Up Your Development Environment on Windows PC
(Android) .......................................................................................................................... 36
See Also......................................................................................................................... 36
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
........................................................................................................................................... 37
Before You Start ........................................................................................................... 37
Step 1: Create a New FireMonkey Application for Android or iOS ..................... 38
Step 2: Select a Style................................................................................................... 39
Step 3: Place Components on the Multi-Device Form .......................................... 39
Step 4: Adding Views to Your Project....................................................................... 43
Step 5: Write an Event Handler for a Button Click by the User ............................. 43
Embarcadero Technologies 3
Step 6: Test Your Mobile Application ........................................................................ 44
Test Your Android Application on the Android Device ..................................... 45
Test Your iOS Application ....................................................................................... 46
See Also......................................................................................................................... 48
Mobile Tutorial: Using an Address Book Component (iOS and Android) ............... 49
Basic Features of the TAddressBook Component .................................................. 50
Creating a Sample Application ................................................................................ 50
Designing the User Interface.................................................................................. 50
Retrieving the Contacts List ................................................................................... 54
Implementing the Control Elements Functionality ............................................. 56
Keeping Address Book in Sync .............................................................................. 60
Configuring Access to Address Book ................................................................... 61
Running the Sample Application .............................................................................. 63
See Also......................................................................................................................... 66
Code Samples.......................................................................................................... 66
Mobile Tutorial: Using a Button Component with Different Styles (iOS and
Android)............................................................................................................................ 67
Buttons in Mobile Platforms ........................................................................................ 67
Define the Look and Feel for a Button Component .............................................. 69
Using TintColor and IconTintColor on Buttons ..................................................... 71
Using Styled and Colored Buttons on Target Platforms ..................................... 72
Customizing Buttons with Styles ............................................................................. 72
Placing an Image over a Button ........................................................................... 73
Create a Segmented Control Using Button Components ................................... 74
Create a Scope Bar on a Toolbar Component ..................................................... 76
Important Differences Between a TButton and TSpeedButton ............................ 77
See Also......................................................................................................................... 77
Using Styled and Colored Buttons on Target Platforms ............................................. 79
See Also......................................................................................................................... 82
Mobile Tutorial: Using a Calendar Component to Pick a Date (iOS and Android)
........................................................................................................................................... 83
Calendar in Mobile Platforms .................................................................................... 83
Implementing an Event Handler for User Changes to the Date .......................... 85
See Also......................................................................................................................... 87
Samples ..................................................................................................................... 87
Mobile Tutorial: Using Combo Box Components to Pick Items from a List (iOS and
Android)............................................................................................................................ 88
Implementing a Picker in Multi-Device Applications ............................................. 88
Building a List of Items Using Code ........................................................................... 91
Displaying a Specific Item.......................................................................................... 91
Implementing an Event Handler for the User's Selection ...................................... 93
See Also......................................................................................................................... 95
Samples ..................................................................................................................... 95
Embarcadero Technologies 4
Mobile Tutorial: Using a Map Component to Work with Maps (iOS and Android)
........................................................................................................................................... 96
Basic Features of the TMapView Component ........................................................ 97
Creating a Sample Application ................................................................................ 97
Configuring Android Applications to Use the TMapView component ........... 97
Designing the User Interface.................................................................................. 97
Running the Sample Application ............................................................................ 102
See Also....................................................................................................................... 104
Code Samples........................................................................................................ 104
Configuring Android Applications to Use Google Maps ........................................ 105
Getting the Google Maps API key ......................................................................... 105
Retrieving Your Application Certificate ............................................................. 105
Creating an API Project in the Google APIs Console ...................................... 107
Requesting a Maps API Key ................................................................................. 107
Configuring Specific Project Options ..................................................................... 108
See Also....................................................................................................................... 110
Code Samples........................................................................................................ 110
Mobile Tutorial: Using a MultiView Component to Display Alternate Views of
Information (iOS and Android).................................................................................... 111
About the TMultiView Component......................................................................... 111
Master Pane Presentation Modes ....................................................................... 113
Designing the User Interface ................................................................................... 120
Designing the Master Pane .................................................................................. 120
Designing the Detail Pane.................................................................................... 121
Implementing the Camera Buttons Functionality ............................................ 121
Setting the TMultiView Component Properties ................................................. 126
Running the Example Application .......................................................................... 126
Mobile Product Samples that Use TMultiView ....................................................... 127
See Also....................................................................................................................... 127
Mobile Tutorial: Using the Web Browser Component (iOS and Android) ............ 128
Design the User Interface ......................................................................................... 129
Write an Event Handler to Open a Web Page when the User Changes the URL
in the Edit Control ...................................................................................................... 132
Implement a Common Method to Open a Web Page .................................. 133
Implement an Event Handler for the OnChange Event ................................. 134
Implement an Event Handler for the Back Button ........................................... 135
Selecting the Proper Virtual Keyboard for the Web Browser Application ....... 136
WebBrowser Mobile Code Snippet ........................................................................ 138
See Also....................................................................................................................... 138
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android) .... 139
Using the Native Style for Tabs on iOS and Android ........................................ 139
Designing Tab Pages Using the Form Designer .................................................... 140
Comparing the Tab Settings on iOS and Android ............................................ 146
Using Custom Multi-Resolution Icons for Your Tabs .............................................. 151
Embarcadero Technologies 5
Displaying Multi-Resolution Custom Icons on Tabs ........................................... 152
Using a Single-Resolution Bitmap for a Custom Icon ....................................... 155
Defining Controls within a TabControl ................................................................... 157
Changing the Page at Run Time ............................................................................ 159
By the User Tapping the Tab ................................................................................ 159
By Actions and an ActionList ............................................................................... 159
By Source Code ..................................................................................................... 165
See Also....................................................................................................................... 167
Samples ................................................................................................................... 167
Mobile Tutorial: Using LiveBindings to Populate a ListView (iOS and Android) ... 168
Step 1: Creating the Project .................................................................................... 168
Step 2: Adding Fields ................................................................................................ 170
Step 3: Creating LiveBindings .................................................................................. 171
Step 4: Adding More Fields (Bitmaps, Currency) .................................................. 173
Step 5: Adding the onButtonClick Event Handler ................................................ 175
The Results................................................................................................................... 175
See Also....................................................................................................................... 177
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and
Android).......................................................................................................................... 178
Using ListBox Components to Display a Table View in Mobile Platforms .......... 178
Plain List ................................................................................................................... 178
Grouped List ........................................................................................................... 179
Search Box .............................................................................................................. 180
Create Items on the ListBox Component .............................................................. 181
Add a Header ........................................................................................................ 183
Add a Group Header/Footer to the List............................................................. 184
Show List Items as Separate Grouped Items ..................................................... 186
Add a Check Box or Other Accessory to a ListBox Item ................................. 186
Add an Icon to a ListBox Item .............................................................................. 187
Add Detail Information to an Item ...................................................................... 187
Running Your Application .................................................................................... 188
Create Your ListBox Application ............................................................................. 188
Add Items to a ListBox from Your Code ............................................................. 189
Create an Overflow Menu ................................................................................... 192
Creating the Event Handler for the Overflow Button ...................................... 194
Add a Search Box.................................................................................................. 195
Running Your Application .................................................................................... 195
See Also....................................................................................................................... 196
Mobile Tutorial: Using LiveBindings to Populate a ListBox in Mobile Applications
(iOS and Android) ......................................................................................................... 197
Step 1: Creating the Project .................................................................................... 197
Step 2: Creating the LiveBindings ........................................................................... 200
The Results................................................................................................................... 203
See Also....................................................................................................................... 204
Embarcadero Technologies 6
Mobile Tutorial: Using Layout to Adjust Different Form Sizes or Orientations (iOS
and Android) ................................................................................................................. 205
Every FireMonkey Component Can Have an Owner, a Parent, and Children
...................................................................................................................................... 205
Using Common Layout-Related Properties of a FireMonkey Component ...... 205
Using the Align Property........................................................................................ 205
Using the Margins Property................................................................................... 207
Using the Padding Property ................................................................................. 207
Using the Anchors Property .................................................................................. 208
Using the TLayout Component ............................................................................... 210
See Also....................................................................................................................... 210
Mobile Tutorial: Taking and Sharing a Picture, and Sharing Text (iOS and Android)
......................................................................................................................................... 211
Topics .......................................................................................................................... 214
See Also....................................................................................................................... 214
Taking and Sharing Pictures and Text Using Action Lists ......................................... 215
Building the User Interface for the Application .................................................... 215
Taking a Picture with a Mobile Device Camera .................................................. 216
Saving a Picture to the Device Photo Library ....................................................... 218
Using a Picture from the Mobile Device Photo Library ........................................ 219
Enabling Image Editing ............................................................................................ 220
Sharing or Printing a Picture ..................................................................................... 222
Sharing Text ................................................................................................................ 224
See Also....................................................................................................................... 226
Samples ................................................................................................................... 226
Taking Pictures Using FireMonkey Interfaces ............................................................ 227
Building the User Interface for Your Application .................................................. 227
Taking a Picture with a Device Camera ............................................................... 228
Running the Application....................................................................................... 231
Saving a Picture to the Device Photo Library ................................................... 231
Selecting a Picture from the Device Photo Library .............................................. 232
See Also....................................................................................................................... 234
Mobile Tutorial: Using Location Sensors (iOS and Android) .................................... 235
Design the User Interface ......................................................................................... 236
The Location Sensor .................................................................................................. 237
Read Location Information (Latitude, Longitude) from the LocationSensor
Component................................................................................................................ 238
Show the Current Location Using Google Maps via a TWebBrowser
Component................................................................................................................ 239
Use Reverse Geocoding .......................................................................................... 240
Show a Readable Address in the ListBox Component ........................................ 243
Describing Why Your Application Needs the User Location .............................. 244
See Also....................................................................................................................... 245
Samples ................................................................................................................... 245
Embarcadero Technologies 7
Mobile Tutorial: Using Notifications (iOS and Android)............................................ 246
Three Basic Notification or Alert Styles ................................................................... 246
Notification Banner on Mobile Devices ............................................................. 246
Alert Dialogs: iOS Badge Number and Android Notification Number .......... 246
Notification Center on Mobile Devices ................................................................. 247
Access the Notification Service .............................................................................. 247
Add FMLocalNotificationPermission (iOS) ............................................................. 248
Set the Icon Badge Number and Notification Number from Code ................. 249
Schedule Notification ............................................................................................... 251
Repeat a Notification Message .............................................................................. 253
Update or Cancel a Scheduled or Repeated Notification Message .............. 255
Present the Notification Message Immediately ................................................... 256
Customizing the Notification Sound ....................................................................... 258
Notification Banner or Notification Alert ................................................................ 262
Add Action to the Notification Alert (iOS Only).................................................... 263
Add Action to Notifications ..................................................................................... 265
Running the Application .......................................................................................... 266
See Also....................................................................................................................... 267
Samples ................................................................................................................... 267
Mobile Tutorial: Using Remote Notifications (iOS and Android) ............................ 268
Remote Push Notification ........................................................................................ 268
REST BAAS framework ............................................................................................... 269
Topics in this Mobile Tutorial ..................................................................................... 269
See Also....................................................................................................................... 269
Code Samples........................................................................................................ 269
Multi-Device Application to Receive Push Notifications ........................................ 270
Design and Set Up the User Interface .................................................................... 270
Creating the Event Handlers ................................................................................... 275
Android Settings......................................................................................................... 278
Project Settings ....................................................................................................... 278
iOS Settings ................................................................................................................. 279
Project Settings ....................................................................................................... 279
Running Your Application on a Mobile Device .................................................... 279
See Also....................................................................................................................... 283
Code Samples........................................................................................................ 283
Mobile Tutorial: Using the Phone Dialer on Mobile Devices (iOS and Android) .. 284
About the Phone Dialer Services on Mobile Devices .......................................... 284
Accessing the Phone Dialer Services ..................................................................... 284
Designing the User Interface ................................................................................... 286
Getting the Carrier Properties ................................................................................. 287
Running the Application....................................................................................... 288
Making a Call ............................................................................................................. 289
Detecting the Call State Changes ......................................................................... 292
Implementing the OnCallStateChanged Event Handler................................ 292
Embarcadero Technologies 8
See Also....................................................................................................................... 296
Samples ................................................................................................................... 296
Mobile Tutorial: Using BaaS for Backend Storage (iOS and Android) ................... 297
Getting Your App Ready in Kinvey and Parse ...................................................... 298
Design and Set Up of the User Interface ............................................................... 298
Adding the Backend Components ........................................................................ 299
Creating and Storing Objects ................................................................................. 301
Deleting Objects........................................................................................................ 302
Retrieving Objects ..................................................................................................... 304
Running Your Application ........................................................................................ 308
See Also....................................................................................................................... 309
Code Samples........................................................................................................ 309
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android) ........... 310
Using dbExpress to Connect to the Database ..................................................... 311
Design and Set Up the User Interface .................................................................... 312
Connecting to the Data .......................................................................................... 313
Deploying Your Application to Mobile .................................................................. 316
Deploy InterBase ToGo, dbExpress Driver, and the Database File to Mobile
.................................................................................................................................. 316
Modify Your Code to Connect to a Local Database File on Mobile ............ 319
Run Your Application on a Simulator or on a Mobile Device ............................ 321
Troubleshooting ......................................................................................................... 322
InterBase Issues ....................................................................................................... 322
Exception Handling Issues .................................................................................... 322
See Also....................................................................................................................... 323
Mobile Tutorial: Using InterBase ToGo with FireDAC (iOS and Android) ............... 324
Using FireDAC to Connect to the Database ........................................................ 326
Design and Set Up the User Interface .................................................................... 326
Connecting to the Data .......................................................................................... 327
Deploying your Application to Mobile................................................................... 332
Deploying InterBase ToGo Required Files and the Database File to Mobile332
Run Your Application on a Simulator or on a Mobile Device ............................ 337
Troubleshooting ......................................................................................................... 337
InterBase Issues ....................................................................................................... 337
Exception Handling Issues .................................................................................... 338
See Also....................................................................................................................... 339
Samples ................................................................................................................... 339
Mobile Tutorial: Using dbExpress and SQLite (iOS and Android) ........................... 340
Using dbExpress to Connect to the Database ..................................................... 341
Creating the Database in the Windows Environment for Development
Purposes ...................................................................................................................... 341
Create the Database in the Data Explorer ....................................................... 341
Create Table on DataExplorer ............................................................................ 344
Design and Set Up the User Interface .................................................................... 345
Embarcadero Technologies 9
Connecting to the Data .......................................................................................... 347
Creating the Event Handler to Make the Delete Button Visible When the User
Selects an Item from the List .................................................................................... 349
Creating the Event Handler for the Add Button to Add an Entry to the List .... 350
Creating the Event Handler for the Delete Button to Remove an Entry from the
List ................................................................................................................................ 356
Setting Up Your Database Deployment for Mobile Platforms ............................ 357
Add and Configure Your Database File in the Deployment Manager ........ 358
Modifying Your Code to Connect to a Local Database File on Mobile
Platforms ..................................................................................................................... 359
Specifying the Location of the SQLite Database on the Mobile Device ..... 359
Creating a Table if None Exists ............................................................................ 360
Running Your Application on a Mobile Device .................................................... 361
See Also....................................................................................................................... 363
Mobile Tutorial: Using FireDAC and SQLite (iOS and Android)............................... 364
Using FireDAC to Connect to the Database ........................................................ 365
Creating the Database using FireDAC framework .............................................. 365
Design and Set Up the User Interface .................................................................... 367
Using the LiveBindings Wizard .................................................................................. 369
Add the LiveBinding components ...................................................................... 369
Connecting to the Data ....................................................................................... 371
Displaying ShopItem in the ListView .................................................................... 373
Creating the Event Handler to Make the Delete Button Visible When the User
Selects an Item from the List .................................................................................... 373
Creating the Event Handler for the Add Button to Add an Entry to the List .... 374
Creating the Event Handler for the Delete Button to Remove an Entry from the
List ................................................................................................................................ 379
Preparing Your Application for Run Time............................................................... 380
Setting Up Your Database Deployment for mobile ............................................. 380
Add and Configure Your Database File in the Deployment Manager ........ 381
Modifying Your Code to Connect to a Local Database File on mobile .......... 382
Specifying the Location of the SQLite Database on the Mobile Device ..... 382
Creating a Table if None Exists ............................................................................ 383
Running Your Application on a Simulator or on a Mobile Device ..................... 384
See Also....................................................................................................................... 386
Mobile Tutorial: Connecting to an Enterprise Database from a Mobile Client (iOS
and Android) ................................................................................................................. 387
Creating the Middle Tier, a DataSnap Server ....................................................... 388
Create a DataSnap Server VCL Application .................................................... 389
Define a DataSet on the DataSnap Server ....................................................... 391
Expose the DataSet from the DataSnap Server ............................................... 394
Run the DataSnap Server ..................................................................................... 395
Creating a Mobile Application that Connects to the DataSnap Server ......... 396
Deploy the MIDAS Library to iOS Simulator ........................................................... 400
Embarcadero Technologies 10
Run Your Application on the mobile platform ...................................................... 400
See Also....................................................................................................................... 401
Mobile Tutorial: Using FireDAC in Mobile Applications (iOS and Android) .......... 402
Using FireDAC to Connect to the Database ........................................................ 402
Design and Set Up the User Interface .................................................................... 403
Using the LiveBindings Wizard .................................................................................. 404
Add the LiveBinding components ...................................................................... 404
Add the ListView component .............................................................................. 406
Using the LiveBindings Wizard .................................................................................. 408
Preparing Your Application for Run Time............................................................... 409
Setting Up Your Database Deployment for mobile ............................................. 409
Add and Configure Your Database File in the Deployment Manager ........ 409
Modifying Your Code to Connect to a Local Database File on Mobile .......... 410
Specifying the Location of the SQLite Database on the Mobile Device ..... 410
Running Your Application on the Simulator or on the Mobile Device .............. 412
See Also....................................................................................................................... 412
Mobile Tutorials: Table of Components Used ........................................................... 413
Embarcadero Technologies 11
Mobile Tutorials: Mobile Application Development (iOS and Android)
o 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 12
Using Basic User Interface Elements
Embarcadero Technologies 13
Using Basic User Interface Elements
Embarcadero Technologies 14
Using Device Functionality
Embarcadero Technologies 15
Using Backend as a Service
Embarcadero Technologies 16
Accessing a Database
Accessing a Database
o Using InterBase ToGo with FireDAC (iOS and
Android)
See Also
o RAD Studio Mobile Tutorials (pdf)
o Multi-Device Preview
Embarcadero Technologies 17
Mobile Tutorial: Set Up Your Development Environment on the Mac (iOS)
A FireMonkey Delphi application destined for the iOS target platform can be
optionally tested on the iOS Simulator available on the Mac. FireMonkey C++
and Delphi applications can be tested using the iOS Device target platform; this
testing requires a test iOS device connected to the Mac.
o 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.
o 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.
o 10.10 Yosemite
o 10.11 El Capitan
o 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)
Embarcadero Technologies 18
Mobile Tutorial: Set Up Your Development Environment on the Mac (iOS)
RAD Studio uses the Platform Assistant to run and debug multi-
device applications and to deploy multi-device applications on
Mac OS X and iOS devices.
o Xcode
Xcode is the development and debug environment on the Mac and provides
the required development files for Mac OS X and iOS applications.
The Mac OS X installer for the Platform Assistant is named PAServer18.0.pkg and
it is available in two places:
Embarcadero Technologies 19
Mobile Tutorial: Set Up Your Development Environment on the Mac (iOS)
http://altd.embarcadero.com/releases/studio/18.0/PAServer/PAServer18.0.
pkg
The Terminal window appears, displaying the Platform Assistant banner and the
password prompt:
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 20
Mobile Tutorial: Set Up Your Development Environment on the Mac (iOS)
For more details about running the Platform Assistant, see Running the Platform
Assistant on a Mac.
Embarcadero Technologies 21
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.
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 22
Additional Steps to Configure Your Mac to Run Your iOS Application on Your iOS Device
To make sure that the Xcode command line tools are installed on your Mac:
4. On the Location window, check that the Command Line Tools shows the
Xcode version (with which the Command Line Tools were installed). This
means that the Xcode Command Line Tools are already installed and you
do not need to install them.
Embarcadero Technologies 23
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.
You are asked for your Apple Developer login during the install process.
For more details, see Installing the Xcode Command Line Tools on a Mac.
Embarcadero Technologies 24
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.
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.
Embarcadero Technologies 25
Additional Steps to Configure Your Mac to Run Your iOS Application on Your iOS Device
Embarcadero Technologies 26
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:
1. Open Xcode on the Mac and go to the Devices (Window > Devices).
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.)
Embarcadero Technologies 27
Additional Steps to Configure Your Mac to Run Your iOS Application on Your iOS Device
See Also
o Mobile Tutorial: Set Up Your Development Environment on Windows PC
(iOS)
Create an Apple ID
Embarcadero Technologies 28
Mobile Tutorial: Set Up Your Development Environment on Windows PC (iOS)
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 29
Mobile Tutorial: Set Up Your Development Environment on Windows PC (iOS)
2. Click Add:
Embarcadero Technologies 30
Mobile Tutorial: Set Up Your Development Environment on Windows PC (iOS)
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 31
Mobile Tutorial: Set Up Your Development Environment on Windows PC (iOS)
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.
Embarcadero Technologies 32
Mobile Tutorial: Set Up Your Development Environment on Windows PC (iOS)
2. Click Add.
Embarcadero Technologies 33
Mobile Tutorial: Set Up Your Development Environment on Windows PC (iOS)
3. On the Add a New SDK dialog box, select iOS Device - 32 bit or iOS
Device - 64 bit as a platform.
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 34
Mobile Tutorial: Set Up Your Development Environment on Windows PC (iOS)
See Also
o Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and
Android)
iAd Network
Embarcadero Technologies 35
Mobile Tutorial: Set Up Your Development Environment on Windows PC (Android)
In order to be able to run applications on an Android device, you also need to:
See Also
o Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and
Android)
Embarcadero Technologies 36
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
Embarcadero Technologies 37
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
Embarcadero Technologies 38
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 39
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
1. Move the mouse pointer over the Tool Palette, and expand the Standard
category by clicking the plus (+) icon next to the category name.
2. Select the TEdit component and either double-click TEdit or drop it onto
the Form Designer.
3. Repeat these steps, but now add a TLabel and a TButton component to
the form.
4. Select the edit box and set the KillFocusByReturn property in the Object
Inspector to True.
5. Select the button and change the Text property in the Object Inspector to
"Say Hello".
6. Now you should see three components on the Form Designer. Here is an
iOS app:
Embarcadero Technologies 40
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.
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:
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).
Embarcadero Technologies 41
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
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):
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 42
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
2. Select the available views you want to add just by clicking on them.
To add a customized view, see Adding a Customized View to the View Selector.
Double-click the button on the Form Designer, and RAD Studio creates skeleton
code that you can use to implement an event handler for the button click
event:
Delphi C++
The following code snippets (Delphi and C++) implement a response that
displays a small dialog box, which reads "Hello + <name entered into the edit
box>":
Delphi code:
C++ code:
Embarcadero Technologies 43
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
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 44
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
Embarcadero Technologies 45
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 46
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
To run your iOS app on a connected iOS device, first select the iOS Device - 32
bit or iOS Device - 64 bit target platform so that the Platform Assistant deploys
the application to the connected iOS Device:
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 47
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 48
Mobile Tutorial: Using an Address Book Component (iOS and Android)
This tutorial describes how to create a simple FireMonkey application that uses
the TAddressBook component.
iOS Android
iPhone 5
Embarcadero Technologies 49
Mobile Tutorial: Using an Address Book Component (iOS and Android)
o Retrieving all contacts from the default source in the device Address
Book.
For Delphi: File > New > Multi-Device Application - Delphi > Blank
Application
For C++: File > New > Multi-Device Application - C++Builder > Blank
Application
Embarcadero Technologies 50
Mobile Tutorial: Using an Address Book Component (iOS and Android)
5. On the Form Designer, right-click TListBox, and then on the shortcut menu,
select Add Item > TSearchBox.
6. In the Tool Palette, select the TMultiView component, and drop it on the
Form Designer.
o The Master Pane provides a form to specify and add a new contact to
the Address Book.
Embarcadero Technologies 51
Mobile Tutorial: Using an Address Book Component (iOS and Android)
After performing the above steps, your Form Designer will be similar to the
following screen:
1. In the Structure View, select MultiView1, and then in the Object Inspector,
specify the following properties:
Embarcadero Technologies 52
Mobile Tutorial: Using an Address Book Component (iOS and Android)
For Label1, Label2, and Label3: set the Text properties to First
Name, Last Name, and Work Mail, respectively.
We recommend that you arrange the control elements of the Master Pane in the
following way:
Embarcadero Technologies 53
Mobile Tutorial: Using an Address Book Component (iOS and Android)
Make the following changes to the Private section of your application code:
Delphi:
private
{ Private declarations }
procedure FillContactList;
procedure AddListBoxItem(Contact: TAddressBookContact);
C++Builder:
Delphi:
Embarcadero Technologies 54
Mobile Tutorial: Using an Address Book Component (iOS and Android)
C++Builder:
}
__finally {
ListBox1->EndUpdate();
}
}
__finally {
Contacts->Free();
}
}
// ---------------------------------------------------------------------------
// Add a new contact to List box
void __fastcall TForm1::AddListBoxItem(TAddressBookContact *Contact) {
TListBoxItem *ListBoxItem = new TListBoxItem(ListBox1);
__try {
ListBoxItem->Text = Contact->DisplayName;
ListBoxItem->Tag = Contact->ID;
ListBox1->AddObject(ListBoxItem);
}
__finally {
ListBoxItem->Free();
}
}
Embarcadero Technologies 55
Mobile Tutorial: Using an Address Book Component (iOS and Android)
2. In the Code Editor, specify the following event handlers for each button:
Delphi:
Embarcadero Technologies 56
Mobile Tutorial: Using an Address Book Component (iOS and Android)
C++Builder:
}
__finally {
ListBox1->EndUpdate();
Contact->Free();
}
}
}
}
// --------------------------For Refresh button--------------------------------
-----
void __fastcall TForm1::btnRefreshClick(TObject *Sender) {
FillContactsList();
}
To implement the onClick event handlers for the Master Pane buttons:
Embarcadero Technologies 57
Mobile Tutorial: Using an Address Book Component (iOS and Android)
3. On the Master Pane, double-click the Add button, and then implement
the following event handler:
For Delphi:
// --------------------------------------------------------------------
// Add a newly created contact to Address Book
procedure TForm1.btnOKClick(Sender: TObject);
var
Contact: TAddressBookContact;
eMails: TContactEmails;
Addresses: TContactAddresses;
begin
Contact := AddressBook1.CreateContact(AddressBook1.DefaultSource);
try
Contact.FirstName := edtFirstName.Text;
Contact.LastName := edtLastName.Text;
// Add the work mail
eMails := TContactEmails.Create;
try
eMails.AddEmail(TContactEmail.TLabelKind.Work, edtWorkMail.Text);
Contact.eMails := eMails;
finally
eMails.Free;
end;
AddressBook1.SaveContact(Contact);
try
ListBox1.BeginUpdate;
AddListBoxItem(Contact);
finally
ListBox1.EndUpdate;
end;
finally
Contact.Free;
end;
MultiView1.HideMaster;
end;
Embarcadero Technologies 58
Mobile Tutorial: Using an Address Book Component (iOS and Android)
For C++:
TContactEmails *eMails;
TAddressBookContact *Contact =
AddressBook1->CreateContact(AddressBook1-
>DefaultSource());
__try {
Contact->FirstName = edtFirstName->Text;
Contact->LastName = edtLastName->Text;
// Add the work mail
eMails = new TContactEmails();
__try {
eMails->AddEmail(TContactEmail::TLabelKind::Work,
edtWorkMail->Text);
Contact->EMails = eMails;
}
__finally {
eMails->Free();
}
AddressBook1->SaveContact(Contact);
__try {
ListBox1->BeginUpdate();
AddListBoxItem(Contact);
}
__finally {
ListBox1->EndUpdate();
}
}
__finally {
Contact->Free();
}
MultiView1->HideMaster();
}
Embarcadero Technologies 59
Mobile Tutorial: Using an Address Book Component (iOS and Android)
For Delphi:
For C++:
1. In the Object Inspector, select AddressBook1, and then open the Events
tab.
For Delphi:
Embarcadero Technologies 60
Mobile Tutorial: Using an Address Book Component (iOS and Android)
For C++:
This section provides the steps to configure your Android and iOS applications to
access the Address Book on the target mobile devices.
1. In the Object Inspector, select Form1, and then open the Events tab.
For Delphi:
end;
Embarcadero Technologies 61
Mobile Tutorial: Using an Address Book Component (iOS and Android)
For C++:
Delphi:
uses
FMX.DialogService;
C++:
#include <FMX.DialogService.hpp>
3. In the Object Inspector, select AddressBook1, and then open the Events
tab.
For Delphi:
end;
Embarcadero Technologies 62
Mobile Tutorial: Using an Address Book Component (iOS and Android)
For C++:
if (AAccessGranted) {
FillContactsList();
}
else {
ShowMessage("You cannot access Address Book. Reason: " +
AMessage);
}
}
1. In the RAD Studio IDE, open Project > Options > Uses Permissions.
Get accounts
Read contacts
Write contacts
Embarcadero Technologies 63
Mobile Tutorial: Using an Address Book Component (iOS and Android)
2. In the Master Pane, enter appropriate information in the First name, Last
name, and Work mail text boxes. When finished, tap Add to add the
newly created contact to Address Book.
Embarcadero Technologies 64
Mobile Tutorial: Using an Address Book Component (iOS and Android)
To delete a contact
Embarcadero Technologies 65
Mobile Tutorial: Using an Address Book Component (iOS and Android)
See Also
o TAddressBook
Code Samples
o Birthday Reminder Sample
Embarcadero Technologies 66
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
Embarcadero Technologies 67
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
Embarcadero Technologies 68
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
Select a component (in this case, a button), and then browse and change the
value of some properties as follows:
o Change the text displayed on the button surface by updating the value
of the Text property in the Object Inspector.
o Change the value of the Position.X and Position.Y properties (or drag the
component using your mouse.)
o Change the value of the Height and/or Width properties (or drag the
edge of the component using your mouse.)
Embarcadero Technologies 69
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
In the StyleLookup drop-down list, you can select a predefined Style based on
how your component is to be used:
Embarcadero Technologies 70
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
o For speed buttons, you need to select a proper StyleLookup value in order
to change the TintColor value in the Object Inspector.
Embarcadero Technologies 71
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
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 72
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
1. In the Form Designer, ensure that you have selected Master from the View
selector.
Edit Custom Style: opens the FireMonkey Style Designer to edit the
styles for selected button.
Edit Default Style: opens the FireMonkey Style Designer to edit the
styles for the selected control class (such as TButton or
TSpeedButton).
For more information about working with custom styles, see the following topics:
o BitmapLinks Editor
2. In the Object Inspector, select TImage and set its Align property to Client.
Embarcadero Technologies 73
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
3. In the Structure View, select the button, expand the Image node, and
then click 0 - Empty (1.000).
4. In the Object Inspector, click the ellipsis button (...) next to Bitmap.
Set the Height and Width properties of TButton to the actual height
and width of your image.
Embarcadero Technologies 74
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
1. Place three TSpeedButton components from the Tool Palette. Place the
TSpeedButton components next to each other using your mouse:
iOS Android
5. Select each component, and change the Text property as you like:
iOS Android
Embarcadero Technologies 75
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
Embarcadero Technologies 76
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
Use the same TSpeedButton controls as in the previous steps, but with the
following values for the StyleLookup property (only available on iOS target
platform):
o toolbuttonleft
o toolbuttonmiddle
o toolbuttonright
(on the Android target platform set StyleLookup as toolbutton for each of the
buttons.)
iOS Android
o 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 Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and
Android)
o FMX.Controls Sample
o FMX.StdCtrls.TButton
o FMX.StdCtrls.TSpeedButton
Embarcadero Technologies 77
Mobile Tutorial: Using a Button Component with Different Styles (iOS and Android)
o FMX.Controls.TStyledControl.StyleLookup
o FMX.StdCtrls.TToolBar
o FMX.StdCtrls.TCustomButton.IconTintColor
o FMX.StdCtrls.TCustomButton.TintColor
o FMX.StdCtrls.TToolBar.TintColor
Embarcadero Technologies 78
Using Styled and Colored Buttons on Target Platforms
ActionToolButton X X X X o
ActionToolButtonBordered X X X o
AddItemButton X X X X
AddItemButtonBordered X – –
AddToolButton X X X X o
AddToolButtonBordered X X X o
ArrowDownToolButton X X X X o
ArrowDownToolButtonBordered X X X o
ArrowDownToolButtonBorderedRight X X X o
ArrowLeftToolButton X X X X o
ArrowLeftToolButtonBordered X X X o
ArrowRightToolButton X X X X o
ArrowRightToolButtonBordered X X X o
ArrowUpToolButton X X X X o
ArrowUpToolButtonBordered X X X o
ArrowUpToolButtonBorderedLeft X X X o
BackToolButton X X X X o
BackToolButtonLabel X X – –
BookmarksToolButton X X X X o
BookmarksToolButtonBordered X X X o
Embarcadero Technologies 79
Using Styled and Colored Buttons on Target Platforms
ButtonStyle XXXXo
ButtonStyleLabel XX – –
CameraToolButton XXXX o
CameraToolButtonBordered XXX o
ClearEditButton XXXX
ColorButtonStyle XXXX
ComposeToolButton XXXX o
ComposeToolButtonBordered X X X o
CornerButtonStyle XXXX
DeleteItemButton XXXX
DeleteItemButtonBordered X – –
DeleteToolButton XXXX
DetailsToolButton XXXX o
DetailsToolButtonBordered XXX o
DoneToolButton XXXX
DropDownEditButton XX – –
EllipsesEditButton XX – –
ForwardToolButton XXXX o
ForwardToolButtonBordered XXX o
InfoToolButton XXXX o
InfoToolButtonBordered XXX o
ListItemButton X XXo
ListItemDeleteButton XXXX
NextToolButton XXXX o
NextToolButtonBordered XXX o
OrganizeToolButton XXXX o
OrganizeToolButtonBordered X X X o
Embarcadero Technologies 80
Using Styled and Colored Buttons on Target Platforms
PageCURLToolButton XXXX o
PasswordEditButton XX – –
PauseToolButton XXXX o
PauseToolButtonBordered XXX o
PlayToolButton XXXX o
PlayToolButtonBordered XXX o
PriorToolButton XXXX o
PriorToolButtonBordered XXX o
RadioButtonStyle XXXX
RefreshToolButton XXXX o
RefreshToolButtonBordered XXX o
ReplyToolButton XXXX o
ReplyToolButtonBordered XXX o
RewindToolButton XXXX o
RewindToolButtonBordered XXX o
SegmentedButtonLeft** XXXXo
SegmentedButtonMiddle** XXXXo
SegmentedButtonRight** XXX o
SearchEditButton XXXX
SearchToolButton XXXX o
SearchToolButtonBordered XXX o
SpeedButtonStyle XXXX
SpeedButtonStyleLabel XX – –
SpinEditButton XXXX
StepperButtonLeft XXXXoo
StepperButtonRight XXXXoo
StopToolButton XXXX o
Embarcadero Technologies 81
Using Styled and Colored Buttons on Target Platforms
StopToolButtonBordered XXX o
ToolButton XXXX
ToolButtonLabel XX – –
ToolButtonLeft XXX o
ToolButtonMiddle XXX o
ToolButtonRight XXX o
TransparentCircleButtonStyle X X X X
TrashToolButton XXXX o
TrashToolButtonBordered XXX o
Notes
* The TintColor and IconTintColor properties are only available on
mobile platforms (iOS and Android) and only for certain
StyleLookup values.
** The SegmentedButtonLeft, SegmentedButtonMiddle, and
SegmentedButtonRight styles are only available for
theTSpeedButton component.
Table legeng:
See Also
o Mobile Tutorial: Using a Button Component with Different Styles (iOS and
Android)
o TButton
o TSpeedButton
Embarcadero Technologies 82
Mobile Tutorial: Using a Calendar Component to Pick a Date (iOS and Android)
iPad2
LG-E612
Embarcadero Technologies 83
Mobile Tutorial: Using a Calendar Component to Pick a Date (iOS and Android)
1. Select the TDateEdit component in the Tool Palette, and drop the
component onto the Form Designer. To find the component in the Tool
Palette, enter the first few characters (such as "dat") in the search box (
):
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 84
Mobile Tutorial: Using a Calendar Component to Pick a Date (iOS and Android)
2. In the Object Inspector, open the Events page, and double-click the
empty space next to OnChange.
Embarcadero Technologies 85
Mobile Tutorial: Using a Calendar Component to Pick a Date (iOS and Android)
Delphi:
C++Builder:
Embarcadero Technologies 86
Mobile Tutorial: Using a Calendar Component to Pick a Date (iOS and Android)
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)
o Mobile Tutorial: Using Combo Box Components to Pick Items from a List
(iOS and Android)
o FMX.DateTimeCtrls.TDateEdit
Samples
o Date Picker sample
Embarcadero Technologies 87
Mobile Tutorial: Using Combo Box Components to Pick Items from a List (iOS and Android)
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 88
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).
Embarcadero Technologies 89
Mobile Tutorial: Using Combo Box Components to Pick Items from a List (iOS and Android)
8. Select the TComboBox component and in the Object Inspector, set the
TComboBox.Align property to Top.
10. Select ComboBox2 and in the Object Inspector, set the TComboBox.Align
property to Bottom.
11. Run the application on your chosen mobile target platform (iOS Simulator
(for Delphi only), iOS Device, or Android Device).
After you tap a TComboBox, the Picker control appears, and you can
select an item.
Embarcadero Technologies 90
Mobile Tutorial: Using Combo Box Components to Pick Items from a List (iOS and Android)
Delphi:
C++Builder:
Embarcadero Technologies 91
Mobile Tutorial: Using Combo Box Components to Pick Items from a List (iOS and Android)
To display the list with the fifth item selected ("California"), specify ItemIndex for
ComboBox1 as follows:
Delphi:
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");
end;
C++Builder:
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");
}
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 92
Mobile Tutorial: Using Combo Box Components to Pick Items from a List (iOS and Android)
2. In the Object Inspector, open the Events page, and double-click the
empty space next to OnChange.
Delphi:
C++Builder:
This event handler displays a message dialog that indicates the item that was
selected.
Embarcadero Technologies 93
Mobile Tutorial: Using Combo Box Components to Pick Items from a List (iOS and Android)
In the Delphi code, the Format function returns a formatted string assembled
from a format string and an array of arguments:
Android (LG - E612) iOS6 (iPad)
Embarcadero Technologies 94
Mobile Tutorial: Using Combo Box Components to Pick Items from a List (iOS and Android)
See Also
o Mobile Tutorial: Using a Calendar Component to Pick a Date (iOS and
Android)
o Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
Samples
o FireMonkey Custom Picker sample
Embarcadero Technologies 95
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 96
Mobile Tutorial: Using a Map Component to Work with Maps (iOS and Android)
o Four Types of Maps: Normal, Satellite, Hybrid, and (for Android only) Terrain
o Control the Map View: Ability to control the map properties, such as the
map center coordinates, the map orientation, and so on
You also need to configure some permissions and project options for your
application.
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 97
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.
5. In the Object Inspector, set the Align properties of the toolbars to Top and
Bottom, respectively.
o In the Tool Palette, select the following components and drop them onto
the top toolbar:
1. In the Form Designer, select TrackBar1 and set the Max property to 359.
2. Select Edit1, and set the Name and Text properties to edLat and 0.0,
respectively.
3. Select Edit2, and set the Name and Text properties to edLong and 0.0,
respectively.
1. In the Tool Palette, select the TLayout component and drop it onto the
bottom toolbar.
3. In the Tool Palette, select three TSpeedButton components, and add them
as child elements of Layout1.
Embarcadero Technologies 98
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 99
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:
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:
To implement the OnChange event handler for the track bar element
2. In the Object Inspector, open the Events tab, and then double-click next
to onChange.
Specify the following code:
Delphi:
C++Builder:
Delphi:
C++Builder:
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.
2. In the Object Inspector, open the Events tab, and double-click next to
OnMapClick.
Delphi:
C++Builder:
2. Specify the new map center (by default the map center is (0.0, 0.0)):
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).
4. Tap the track bar element, and then move the slide indicator by dragging
it to a particular location. [This changes the map orientation (bearing).
The map orientation is the direction in which a vertical line on the map
points, measured in degrees clockwise from north.]
iOS Android
iPad
See Also
o TMapView
Code Samples
o Tabbed Map Sample
o Map Sample
2. Register a project in the Google APIs Console and add the Maps API as a
service for the project.
Note: This section explains how to retrieve the debug certificate. For
information on how to retrieve the release certificate, see Get an
Android certificate and the Google Maps API key.
Tip: If you cannot find the debug.keystore file in the above mentioned location,
run your application on the Android target platform, and then RAD Studio
automatically creates this file.
3. Switch to the folder where the debug.keystore file is located and run:
keytool -list -v -keystore debug.keystore -alias androiddebugkey
-storepass android -keypass android
Tip: You need to add the full path to keytool; if the keytool.exe file is located in
the example provided above, you can use the following:
"C:\Program Files\Java\jdk1.7.0_71\bin\keytool" -list -v -keystore
debug.keystore -alias androiddebugkey -storepass android -keypass
android
Note: If you have not used the Google APIs Console before,
you are prompted to create a project that you use to track
your usage of the Google Maps Android API. Click Create
Project to create a new project called API Project. On the
next page, this name appears in the upper left-hand corner.
3. In the list of services, scroll down until you see Google Maps Android API
v2.
4. To the right of the entry, click the switch indicator so that it is on.
This displays the Google Maps Android API Terms of Service.
5. If you agree to the terms of service, click the checkbox below the terms of
service, and then click Accept.
This returns you to the list of APIs and services.
2. In the Services page, verify that the "Google Maps Android API v2" is
enabled.
5. In the resulting dialog, enter the SHA-1 fingerprint, then a semicolon, and
then the package name of your application. For example:
0B:4D:1E:83:2F:91:3A:BD:92:EB:87:62:6D:34:66:9D:6A:51:3B:ED;my.co
mpany.Mymap
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
1. In the RAD Studio IDE, open Project > Options > Uses Permissions
1. In the RAD Studio IDE, open Project > Options > Entitlement List
1. In the RAD Studio IDE, open Project > Options > Version Info
2. Set the apiKey key to the Maps API key value that you have requested for
your application (see Step 6 in the Requesting a Maps API Key section
earlier in this document).
3. Click OK.
See Also
o TMapView
o Mobile Tutorial: Using a Map Component to Work with Maps (iOS and
Android)
Code Samples
o Tabbed Map Sample
o Map Sample
o The master pane can display a collection of any visual controls, such as
edit boxes, labels, lists, and so forth.
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:
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.
To expand the navigation panel to display all child controls, tap the Master
button specified in the TMultiView.MasterButton property.
Device Orientation
Device Type Master Pane Presentation
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:
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.
For Delphi:
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.
2. Drop two TButton components into the TMultiview container, and then in
the Object Inspector specify the following properties of those buttons:
3. Drop a TLabel component into the TMultiview container, and then in the
Object Inspector, set its Text property to Camera type:.
4. Drop two TButton components into the TMultiview container, and then in
the Object Inspector specify the following properties of those buttons:
4. Drop the TImage into the TPanel container, and set the following
properties:
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.
1. On the Form Designer, double-click the Start Camera button, and insert
the following code:
For Delphi:
For C++:
2. Double-click the Stop Camera button, and insert the following code:
For Delphi:
For C++:
For Delphi:
For C++:
For Delphi:
For C++:
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++:
For Delphi:
procedure TForm1.GetImage;
begin
CameraComponent1.SampleBufferToBitmap(imgCameraView.Bitmap, True);
end;
For C++:
o TargetControl = Panel1
o Mode = Drawer
o Visible = True
o 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.)
3. To open the master panel, swipe right from the left edge of the device
screen.
4. To activate the device camera, on the master panel, click Start Camera.
5. Optionally, you can select the front or back camera (if available) by using
the Front or Back button, respectively.
See Also
o FMX.MultiView.TMultiView
o FMX.MultiView.TMultiViewPresentation
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.
5. Select the TButton component on the Form Designer, and then in the
Object Inspector, set the StyleLookup property to priortoolbutton.
image:
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.
After you complete these steps, the form should be similar to the following
picture:
iPad
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.
1. In the private section of the TForm1 class, declare the OpenURL method:
Delphi:
private
{ Private declarations }
procedure OpenURL;
C++Builder:
Delphi:
procedure TForm1.OpenURL;
begin
WebBrowser1.Navigate(Edit1.Text);
end;
C++Builder:
Delphi:
C++Builder:
Delphi:
C++Builder:
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.
The most appropriate Virtual Keyboard type for Web Browser components is URL.
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.
o Subversion
Repository:http://sourceforge.net/p/radstudiodemos/code/HEAD/tree/br
anches/RADStudio_Berlin/Object%20Pascal/Mobile%20Snippets/WebBrow
ser
See Also
o Mobile Tutorial: Using Combo Box Components to Pick Items from a List
(iOS and Android)
o Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
o FMX.KeyboardTypes Sample
o TWebBrowser
o TToolBar
o TButton
o TEdit
o KeyboardType
o StyleLookup
o On Android:
Tabs are commonly placed at the top of the screen (so you should
set TTabPosition either to Top or to PlatformDefault).
o 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.
1. Select:
For Delphi: File > New > Multi-Device Application - Delphi > Blank
Application
For C++: File > New > Multi-Device Application - C++Builder > Blank
Application
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:
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.
7. On the Form Designer, select the first TabItem and change its StyleLookup
property:
iOS
Android
10. 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:
Top
iOS Android
Bottom
iOS Android
Dots
iOS 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.
Platform Default
iOS Android
Notes:
o In Android apps, predefined icons are not supported, so you must use
custom icons.
o In iOS apps, you can use either predefined icons or custom icons.
o 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.
o For iOS, you can use our predefined icons by setting the StyleLookup
o The custom glyphs used in this section are available in a zip file that is
delivered in your C:\Program Files
(x86)\Embarcadero\Studio\18.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.
2. Select a tab, and click the ellipsis button [...] on the CustomIcon property
of TTabItem in the Object Inspector:
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:
When you have added all the scales you want, the editor
looks like this:
6. Click the Fill All from File button , navigate to an image file you want
to use, and then click Open.
The selected image now appears appropriately scaled in each of the Scale
entries on the MultiResBitmap Editor:
8. Repeat Steps 2 to 7 for each of the remaining tabitems, and assign each
tabitem a custom icon image.
After you define a custom icon, the FireMonkey framework generates a Selected
Image and Non-Selected (dimmed) Image based on the given .png file. This
transformation is done using the Alpha-Channel of the bitmap data. For
example:
Original Image Selected Image Non-Selected Image
To specify a single-resolution bitmap for a custom icon, perform the first step of
the procedure above and then proceed as follows:
2. Now, in the Object Inspector, click the ellipsis button [...] in the Bitmap field
(of the TabItem1.CustomIcon[0]). This opens the Bitmap Editor:
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:
Android
o 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:
2. From the Tool Palette, add a TActionList component to the form, and then
add a TButton to TabItem1:
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):
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.
8. On the Form Designer, select Button2 and in the Object Inspector, select
Action | New Standard Action | Tab > TPreviousTabAction from the drop-
down menu.
9. On the Form Designer, select Button3 and in the Object Inspector, select
Action | New Standard Action | Tab > TNextTabAction from the drop-
down menu.
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.
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.
Delphi:
TabControl1.ActiveTab := TabItem1;
C++:
TabControl1->ActiveTab = TabItem1;
Delphi:
TabControl1.TabIndex := 2;
C++:
TabControl1->TabIndex = 2;
Delphi:
// You can set the target at run time if it is not defined yet.
ChangeTabAction1.Tab := TabItem2;
C++:
// You can set the target at run time if it is not defined yet.
ChangeTabAction1->Tab = TabItem2;
See Also
o Mobile Tutorial: Using a Button Component with Different Styles (iOS and
Android)
o Mobile Tutorial: Using the Web Browser Component (iOS and Android)
Samples
o Tab Sliding
Like every LiveBinding, this tutorial requires no code. However, in order to create
a useful application, you do need to add event handlers and other code.
2. In the Tool Palette, locate a TListView component and drop it onto 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.
2. From the Add Field dialog box, select ColorsNames and click OK.
The ListView component automatically populates its items with color names from
the prototyping data component:
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.
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.
2. In the Add Field dialog box, Ctrl+Click to select Bitmaps and Currency
field data. When finished, click OK.
This step adds a button representing the color and number of each list view item,
such as Blue 19.
This step displays the currency field value on the button located on the right-
hand side of each list view item.
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.
2. In the Object Inspector, open the Events tab, and then double-click
OnButtonClick.
The following sample code adds the event handler that displays a message box
when you click a ListView item:
Delphi:
C++Builder:
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 Android
iPad Galaxy S4
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)
o FMX.ListView.TListView
o TPrototypeBindSource
o LiveBindings Designer
Plain List
iOS Android (LG E-612)
Grouped List
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 multi-
device applications for mobile platforms.
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. To find TListBox, enter a few characters (such as "TList") in the
Search box of the Tool Palette:
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:
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:
Property Value
Align Client
StyleLookup toollabel
TextSettings.HorzAlign
Center
3. Select TListBoxGroupFooter from the drop-down list, and then select Add
Item.
5. Close the dialog box. Now you have a Group Header and a Group Footer
on the TListBox component.
You can select the GroupingKind property and the StyleLookup property in the
Object Inspector when the ListBox is selected in the Form Designer.
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.
Specify additional text in the ItemData.Detail property, and select the location of
the Detail Text through the StyleLookup property, as shown in the following table:
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.
o Delphi:
ListBox1.Items.Add('Text to add');
o 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 Android (LG E-612)
Delphi:
// 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);
C++:
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);
1. Add a TToolBar component on the form and set the alignment to Top.
Check akTop and akRight from the Anchors property of the TListBox
component.
Change the Text property to the text value that you want.
o Delphi:
o C++:
Delphi:
C++:
2. To invoke the overflow menu, click the vertical ellipsis on the Action bar.
See Also
o FMX.ListBox.TListBox
o Mobile Tutorial: Using a Button Component with Different Styles (iOS and
Android)
o Mobile Tutorial: Using the Web Browser Component (iOS and Android)
o Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android)
1. Select:
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.
At this point, your form should be similar to the following iOS screen:
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.
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.
At this point, the list box groups all the color names into alphabetical categories:
7. Click the ellipsis button [...] on the Rectangle1 diagram block in the
LiveBindings Designer, and in the dialog that opens, type Fill.Color. Select
the Fill.color check box, then click OK:
After you complete the steps above, the LiveBindings diagram will be similar to
the following image:
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:
See Also
o LiveBindings in RAD Studio
o LiveBindings Designer
o Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
If you add components (for example, a Button, Label, and others) to another
component (for example, a ToolBar), the ToolBar is both parent and owner of the
Button, Label, and others. You can see this parent-child relationship graphically
represented in the tree view in the Structure View.
The Layout for a child is defined as a value relative to its parent. In the following
picture, Label1 is the child of Toolbar1, and the Layout of Label1 is relative to
Toolbar1.
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).
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.
In the following picture, the right side of the component (Align = Client) uses the
Margins property to ensure space around the component.
o Left
o Right
o Bottom
o Top
In the following picture, the parent component (which contains two regions)
uses the Padding property to ensure space inside the parent component:
If you want the Edit control to maintain the same relative position in relation to
the ToolBar (its parent), you can set the Anchors property to akLeft, akTop,
akRight. When the ToolBar is resized, the Edit control is resized according to the
Anchors settings:
iOS
Android
iOS:
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.
See Also
o Mobile Tutorial: Using LiveBindings to Populate a ListView (iOS and
Android)
o Gestures in FireMonkey
o 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:
Using a picture from the device Photo
Taking a picture with the device camera
Library
On Android Devices:
Taking a picture with the device camera Using a picture from the device Photo Library
Topics
o Taking and Sharing Pictures and Text Using Action Lists
See Also
o Mobile Tutorial: Using Location Sensors (iOS and Android)
o FireMonkey Actions
o FMX.StdCtrls.TButton
o FMX.Objects.TImage
o FMX.MediaLibrary
o FMX.PhotoEditorDemo Sample
o FMX.CameraComponent Sample
o http://appleinsider.com/articles/12/02/16/share_sheets
In this tutorial, you learn how to assign actions to user interface elements (such as
a button) for each functionality that you want to support.
o TToolBar component
Set the StyleLookup property for the three buttons respectively to:
cameratoolbuttonbordered
searchtoolbuttonbordered
actiontoolbuttonbordered
o TImage component
o TActionList component
The form should now look like the following screen, before you set the Style or
View in the Form Designer:
Note: For information about the selection of the Style and Views,
see Style Selector and Using FireMonkey Views.
1. On the Form Designer, select the button (to be used for taking a photo).
2. In the Object Inspector, select the drop-down list for the Action property.
4. On the Events tab, expand the Action node, and then double-click the
OnDidFinishTaking event.
Delphi:
C++:
This code assigns a picture taken from the mobile device camera to the Bitmap
property of the TImage component.
1. In the Structure View, expand the ActionList1 node, and then select
TakePhotoFromCameraAction1.
Your application saves the pictures to an album in the device Photo Library. The
album name depends on the device operating system in the following way:
Android Camera
Note: To save an image instead of a photo to the Photo Library, you can use
IFMXPhotoLibrary.AddImageToSavedPhotosAlbum.
1. On the Form Designer, choose the button that you want to use (for
picking up a photo).
2. In the Object Inspector, click the drop-down list for the Action property
and select New Standard Action | Media Library |
TTakePhotoFromLibraryAction.
3. In the Events tab, expand the Action node, and then double-click the
OnDidFinishTaking event.
Delphi:
C++:
The code above assigns a picture taken from the Photo Library to the Bitmap
property of the TImage component.
1. ActionList1 | TakePhotoFromCameraAction1
2. ActionList1 | TakePhotoFromLibraryAction1
After enabling the Editable property, you can crop the photos on iOS and
Android.
On iOS Devices:
Loading the Picture Zooming the Picture Cropping the Picture
On Android Devices:
Loading the Picture Android Menu for the Action Cropping the Picture
This multi-share service is called Share Sheet Functionality, and you can
implement this functionality using the following steps:
2. In the Object Inspector, click the drop-down list for the Action property,
and select New Standard Action | Media Library |
TShowShareSheetAction.
3. On the Events tab, expand the Action node, and then double-click the
OnBeforeExecute event.
Delphi:
C++:
The code above assigns a picture on the TImage component to "Share Sheet
Functionality".
After you select Facebook from the list of services, you can post the picture on
Facebook with your comment:
For a sample application that uses share sheet functionality, see the
FMX.PhotoEditorDemo Sample.
Sharing Text
From your application, you can share text using the share sheet of the mobile
device. The applications that appear in the share sheet depend on the device:
From your application, you can share text on social networking sites (such as
Facebook and Twitter), you can send it by email, SMS (Short Message Service),
and other available methods.
You can implement this functionality with the multi-share service called Share
Sheet Functionality. The TShowShareSheetAction is the standard action for
sharing images and text. TShowShareSheetAction shows the available sharing
options depending on the type of content you are sharing. That is, the options
shown for Text are different than for a Bitmap.
TToolBar component
TMemo component
TActionList component
1. On the Form Designer, select the button (for sharing the text).
2. In the Object Inspector, click the drop-down list for the Action property,
and select New Standard Action | Media Library |
TShowShareSheetAction.
3. On the Events tab, expand the Action node, and then double-click the
OnBeforeExecute event.
Delphi:
C++:
The code above uses the TextMessage property to assign the text to be shared,
as previously typed in a TMemo.
See Also
o Taking Pictures Using FireMonkey Interfaces
o FireMonkey Actions
o FMX.StdCtrls.TButton
o FMX.Objects.TImage
o FMX.MediaLibrary
o http://appleinsider.com/articles/12/02/16/share_sheets
Samples
o FireMonkey Photo Editor sample
o TToolBar component
o TImage component
The form this sample application 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.
1. Open the Code Editor and add the following lines to your code if they are
not present:
Delphi:
uses
FMX.MediaLibrary, FMX.Platform, System.Messaging;
C++:
#include <FMX.Platform.hpp>
#include <FMX.MediaLibrary.hpp>
#include <System.Messaging.hpp>
2. Add the following procedure header to the private section of the form
definition:
Delphi:
C++:
Delphi:
Image1.Bitmap.Assign(TMessageDidFinishTakingImageFromLibrary(M).Value);
end;
C++:
Delphi:
C++:
}
else {
ShowMessage("This device does not support the camera
service");
}
}
Your application saves the pictures to an album in the device Photo Library. The
album name depends on the device operation system in the following way:
Android Camera
To let your application select a picture from the device Photo Library, perform
the following steps:
Delphi:
C++:
}
else {
ShowMessage("This device does not support the photo
library service");
}
}
2. In the Structure View, select Form1, in the Object Inspector, open the
Events tab, double-click an empty field next to OnCreate, and then
implement the following onFormCreate event handler:
Delphi:
C++:
3. Compile and run your application. To select a picture, tap the search
button, and then select the picture of interest from the device Photo
Library.
iOS Android
See Also
o Taking and Sharing Pictures and Text Using Action Lists
o FMX.CameraComponent Sample
o FMX.StdCtrls.TButton
o FMX.Objects.TImage
o FMX.MediaLibrary
o IFMXPhotoLibrary
o IFMXCameraService
o Mobile Tutorial: Using the Web Browser Component (iOS and Android)
This tutorial describes the basic steps to locate your mobile device (using latitude
and longitude), and to use Reverse Geocoding to convert to a readable
address, such as in the following picture:
o 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:
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.
Delphi:
C++:
Delphi:
C++:
You can call Google Maps from the TWebBrowser component with the following
URL parameters:
https://maps.google.com/maps?q=(Latitude-value),(Longitude-value)
So you can add this URL to your previously created event handler
OnLocationChanged as follows:
Delphi:
C++:
FormatSettings.DecimalSeparator = LDecSeparator;
WebBrowser1->Navigate(URLString);
}
In this case, we use TGeocoder to "Reverse Geocode" our location (in Latitude
and Longitude) to readable address information.
6. Your iOS App receives the address information through the parameter on
the OnGeocodeReverse event and updates the user interface.
Note: As TGeocoder is not a component (this is just a class), you need to define
these steps through your code (you cannot drop a component, nor assign an
event handler through the Object Inspector).
First, define a new field "FGeocoder" in the private section of the form. You can
also define an "OnGeocodeReverseEvent procedure" as in the following code
snippets.
Delphi:
type
TForm1 = class(TForm)
// IDE defines visible (or non-visual) components here automatically
private
{ Private declarations }
FGeocoder: TGeocoder;
procedure OnGeocodeReverseEvent(const Address: TCivicAddress);
public
{ Public declarations }
end;
C++:
Now you can create an instance of TGeocoder and set it up with data with the
following Delphi or C++ code.
Delphi:
C++:
Delphi:
C++:
See Also
o Mobile Tutorial: Using Layout to Adjust Different Form Sizes or Orientations
(iOS and Android)
o System.Sensors.TGeocoder
o System.Sensors.Components.TLocationSensor
Samples
o Location sample
Android
iPad
Android
Android
3. Check that the following unit has been automatically added to the
project:
For Delphi applications, add the following unit to the uses clause if it
is not present:
uses
System.Notification;
#include <System.Notification.hpp>
To set the iOS icon badge number (for Delphi or C++) or the Android notification
number (only for Delphi apps), you need to implement the corresponding
method.
4. Implement the event handler for the OnClick event of the SetNumber
button by adding the following code:
For Delphi:
For C++:
After running your application (press F9) and clicking the SetNumber button, you
can see the following:
Android
Schedule Notification
You can also schedule Notification Messages using the ScheduleNotification
method that the TNotificationCenter class inherits from
TCustomNotificationCenter.
For Delphi:
For C++:
}
}
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:
Also you need to use the ScheduleNotification method and set the
RepeatInterval property. In the following code, the repeated interval is set to a
minute.
For Delphi:
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:
For Delphi:
begin
NotificationCenter1.CancelNotification('MyNotification');
end;
For C++:
For Delphi:
For C++:
For Delphi:
For C++:
For Delphi:
uses
System.IOUtils;
private
function GetSoundName: string;
For C++:
#include <System.IOUtils.hpp>
private: // User declarations
__fastcall UnicodeString GetSoundName ();
Note: Depending on the target operating system, the sound data should be a
different file extension.
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;
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: .\
Android
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:
To customize an Alert Action, you need to set the AlertAction field to the Action
button name, and then set the HasAction field to True, as follows.
For Delphi:
For C++:
The notification alert opens at the time that was specified through the FireDate
field.
The following code snippet implements a response to show a message box that
says "The <Notification name>" notification clicked."
o For Delphi:
o For C++:
See Also
o Using Notifications
o Mobile Tutorial: Taking and Sharing a Picture, and Sharing Text (iOS and
Android)
Samples
o FireMonkey Send Cancel Notification sample
Both iOS and Android offer built-in support for remote notifications, and RAD
Studio offers a REST BaaS framework that supports the following protocols, cloud
providers and backend service:
o Protocols:
Parse
Kinvey
o 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 user’s attention. For more information, see
Mobile Tutorial: Using Notifications (iOS and Android).
o The term Service Provider covers in this tutorial the Cloud service providers
(Kinvey and Parse) and the backend service provider EMS.
See Also
o BaaS Overview
o Mobile Tutorial: Using BaaS for Backend Storage (iOS and Android)
Code Samples
o BaaS ToDo Sample
Note: Because our implementation is based on the REST BAAS framework, RAD
Studio allows you to use in your iOS or Android apps one of the following service
providers:
o Kinvey
o Parse
o EMS
File > New > Multi-device Application - Delphi > Blank Application
File > New > Multi-device Application - C++Builder > Blank Application
3. Add a TMemo component to the form and set the Align property to
Client.
Note: You do not need to add the GCM AppID when developing Android apps
and using Parse.
Delphi:
implementation
{$R *.fmx}
end.
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("");
}
//-----------------------------------------------------------------------
---
Android Settings
Note: To verify whether your Android device supports GCM, see GCM Overview
Project Settings
To enable your application to receive remote notifications:
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.
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.
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
EMS
Android
iOS EMS
6. Send your app to background and send another push from Parse or
Kinvey. Now go to Notifications:
iOS
Android
See Also
o Mobile Tutorial: Using Notifications (iOS and Android)
o Mobile Tutorial: Using BaaS for Backend Storage (iOS and Android)
o Entitlement List
Code Samples
o BaaS ToDo Sample
The phone dialer services allow you to perform the following operations:
o Make a call.
1. Select:
o 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>
o Only for Delphi apps: Add the following line to the public section of the
form definition:
o Add the following properties to the private section of the form definition:
Delphi:
C++:
o Only for Delphi apps: in the implementation section, override the form
constructor as follows:
o 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:
1. Drop two TLabel components on the Form Designer, and then set their
Name properties to lblCarrierName and lblISOCountryCode, respectively.
2. Set the Text property for the labels to Carrier Name and ISO Country
Code, respectively.
Name to btnGetCarrierInfo
Delphi:
C++:
o Call phone
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.
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.
o On the Events tab, double-click onClick, and then implement the onClick
event handler as follows:
Delphi:
C++:
To make a call:
2. In the TEdit field under Telephone Number, type the phone number.
The following table describes the items in the TCallState enumeration (the
supported states for each platform are marked with "+").
1. Add the following procedure header to the private section of the form
definition:
Delphi:
C++:
Delphi:
TPlatformServices.Current.SupportsPlatformService(IFMXPhoneDialerService,
IInterface(PhoneDialerService));
if Assigned(PhoneDialerService) then
PhoneDialerService.OnCallStateChanged := MyOnCallStateChanged;
end;
C++:
Delphi:
C++:
After you implement this event handler, the application shows the phone call
state.
For example, the following iOS screen indicates that the phone is in a dialing
state:
See Also
o Mobile Tutorial: Taking and Sharing a Picture, and Sharing Text (iOS and
Android)
o FMX.PhoneDialer.IFMXPhoneDialerService
Samples
o FireMonkey Phone Dialer sample
This tutorial creates a Shopping List where the items added are stored in the
cloud by the BaaS provider, so these items can be shared and updated among
different devices if needed.
iOS Android
iPod Nexus 7
With backend storage you can store files and data in the cloud. This information
can later be retrieved, updated, and deleted.
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:
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:
2. Drop a TBackendStorage on the form, and in the Object Inspector set the
Provider property to the BaaS provider component you are using.
Delphi:
C++:
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="";
}
}
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, double-
click the OnDeletingItem event. This event occurs before the item is
deleted. Add the following code:
Delphi:
C++:
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.
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.
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.
Delphi:
procedure TForm1.RefreshList;
var
LJSONArray : TJSONArray;
LItem: TListViewItem;
I: Integer;
begin
LJSONArray := TJSONArray.Create;
try
BackendStorage1.Storage.QueryObjects('ShoppingList', [], LJSONArray);
ListView1.ClearItems;
for I := 0 to LJSONArray.Count-1 do
begin
LItem := ListView1.Items.Add;
LItem.Text := (LJSonArray.Items[I].GetValue<string>('item'));
end;
finally
LJSONArray.Free;
end;
end;
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:
C++:
Delphi:
RefreshList;
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:
C++:
1. In the Project Manager, select the target platform where you want to run
your app.
Note: This app uses the swipe-to-delete feature that is supported on mobile apps
(iOS and Android), as well as desktop apps (Windows and Mac OS X) when
touch input is available.
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 Android
iPod Nexus 7
See Also
o BaaS Overview
Code Samples
o BaaS ToDo Sample
Instead of dbExpress, we recommend that you use our newer database solution,
FireDAC, which is described in a similar tutorial, here:
Mobile Tutorial: Using InterBase ToGo with FireDAC (iOS and Android).
Before starting this tutorial, you should read and perform the following tutorial
session:
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.
o 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:
3. Click the ellipsis [...] for the Params property, and set the Database
value to
C:\Users\Public\Documents\Embarcadero\Studio\18.0\Samples\D
ata\dbdemos.gdb (location of the database).
3. Open the LiveBindings Designer and connect the data and the user
interface as follows:
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).
o Interbase ToGo
1. You can add the database to your project with one of the following two
methods:
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.
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.
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.
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.
Delphi:
C++:
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.
If you encounter a crash, you might want to connect manually to the database
while you troubleshoot the issue using the following steps:
2. Drop a button on the form, and create the following event handler to
manually connect to the database:
Delphi:
C++:
See Also
o InterBase ToGo with dbExpress
o http://www.embarcadero.com/products/interbase/product-editions
Tip: To follow this tutorial, you need a license for IBToGo or IBLite:
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.
o 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:
8. Open the LiveBindings Designer and connect the data and the user
interface as follows:
Note: The Preparing a FireDAC Application for Run Time topic explains the use of
the TFDGUIxWaitCursor and TFDPhysIBDriverLink components in a FireDAC
application.
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).
o Interbase ToGo required file (the license file and other configuration files)
1. You can add the database to your project with one of the following two
methods:
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.
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.
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.
3. Implement the event handler for the BeforeConnect event by adding the
following code:
For Delphi:
implementation
{$R *.fmx}
{$R *.NmXhdpiPh.fmx ANDROID}
{$R *.iPhone4in.fmx IOS}
uses System.IOUtils;
For C++:
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.
If you encounter a crash, you might want to connect manually to the database
while you troubleshoot the issue using the following steps:
2. Drop a button on the form, and create the following event handler to
manually connect to the database:
Delphi:
C++:
See Also
o InterBase ToGo
o Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
o http://www.embarcadero.com/products/interbase/product-editions
Samples
o FireDAC InterBase sample
Instead of dbExpress, we recommend that you use our newer database solution,
FireDAC, which is described in a similar tutorial, here:
Mobile Tutorial: Using FireDAC and SQLite (iOS and Android).
Before starting this tutorial, you should read and perform the following tutorial
session:
This tutorial describes the basic steps to use SQLite as a local data storage on
your mobile device through the dbExpress framework.
iOS Android
o 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.
4. Click the Advanced button and open the Advanced Properties dialog
box.
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.)
To set up a ListBox component and other UI elements, use the following steps:
3. Drop a TButton on the ToolBar component and set the following properties
in the Object Inspector:
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.
1. Select the Item table on the Data Explorer and drag it to the Form
Designer.
3. Select the ItemTable component on the form, and then change the
Active property to True.
4. Select View > LiveBindings Designer and the LiveBindings Designer opens.
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.
o Select ListBox1 and define the following event handler for the OnItemClick
event.
Delphi:
C++Builder:
Delphi:
Declare this procedure prototype under the private section of the Form class:
private
procedure OnInputQuery_Close(const AResult: TModalResult; const AValues:
array of string);
C++Builder:
public:
InputQueryMethod(TInputCloseQueryProcEvent _Event) {
Event = _Event;
}
3. Add the next declaration under the private section of the form:
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
Delphi:
try
SQLQueryDelete.ParamByName('ShopItem').AsString := TaskName;
SQLQueryDelete.ExecSQL();
ItemTable.Refresh;
LinkFillControlToField1.BindList.FillList;
if ListBox1.Selected <> nil then
ButtonDelete.Visible := True
else
ButtonDelete.Visible := False;
except
on e: Exception do
begin
SHowMessage(e.Message);
end;
end;
end;
C++Builder:
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).
1. You can add the database to your project with one of the following two
methods:
2. After adding the database file, the Featured Files window displays, click
Cancel to close it.
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.
You can create a SQLite Database and Table with the following steps:
Delphi:
C++Builder:
Delphi:
C++Builder:
iOS 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 dbExpress (iOS and Android)
This tutorial describes the basic steps to use SQLite as a local data storage on
your mobile device through the FireDAC framework.
iOS Android
o 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.
Note: In the Form Designer, activate the Master view for this tutorial.
For Delphi: File > New > Multi-Device Application - Delphi > Blank
Application
For C++: File > New > Multi-Device Application - C++Builder > Blank
Application
Note: You can set the above Database parameter even if shoplist.s3db does not
exist, RAD Studio creates it automatically. (To display Employees.s3db or other
*.s3db files in the Open dialog, set the All Files (*.*) option.)
To set up a ListView component and other UI elements, use the following steps:
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:
7. Select BindSourceDB1.
Note: These last steps are not mandatory for this tutorial since there is only one
field in BindSourceDB1. These steps are useful to link with the selected value if we
are managing several fields of a database.
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.
o Select ListView1 and define the following event handler for the
OnItemClick event.
Delphi:
o For C++:
o For Delphi:
private
procedure OnInputQuery_Close(const AResult: TModalResult; const AValues:
array of string);
o For C++:
o Add the following definition after the TForm1 definition (in the .h file of your
unit):
o Add the following class definition (in the .h file of your unit, after the
previously defined type):
public:
InputQueryMethod(TInputCloseQueryProcEvent _Event) {
Event = _Event;
}
o Add the following declaration under the private section of the form (in the
.h file of your unit):
o Add the following code (in the .cpp file of your unit):
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
o For Delphi:
try
FDQueryDelete.ParamByName('ShopItem').AsString := TaskName;
FDQueryDelete.ExecSQL();
FDQuery1.Close;
FDQuery1.Open;
ButtonDelete.Visible := ListView1.Selected <> nil;
except
on e: Exception do
begin
SHowMessage(e.Message);
end;
end;
end;
o For C++:
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).
1. You can add the database to your project with one of the following two
methods:
2. After adding the database file, the Featured Files window displays, click
Cancel to close it.
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.
You can create a SQLite Database and Table with the following steps:
o For Delphi:
implementation
{$R *.fmx}
uses System.IOUtils;
o For C++:
System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetDocumentsPath
(), "shoplist.s3db");
#endif
}
o For Delphi:
o For C++:
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)
RAD Studio provides the DataSnap framework with which you can develop the
middle tier (and access the middle tier) with almost no coding required. This
tutorial describes the steps to develop the middle tier and then develop the
mobile client.
3. At the third step, choose the TCP/IP protocol, Server Methods Class
and Sample Methods from the Server Features list.
4. Save the server methods unit (by default as created by the Wizard:
ServerMethodsUnit1) as ServerModuleUnit.
5. Save the server container unit (by default as created by the Wizard:
ServerContainerUnit1) as ServerContainerUnit.
3. In the Form Designer, change the Name property of the Server Module to
DSServerModule_EMPLOYEE.
2. Select DSServerClass1, and update the existing event handler for the
OnGetClass event. Add the following code to the DSServerClass1 event
handler:
Delphi:
procedure TServerContainer1.DSServerClass1GetClass(DSServerClass:
TDSServerClass;
var PersistentClass: TPersistentClass);
begin
PersistentClass := TDSServerModule_EMPLOYEE;
end;
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.
If you see an error, please double-check the properties you have just set.
TListBox component
7. Open the LiveBindings Designer and connect the data and user interface
as follows:
o MIDAS Library
3. Select the following module, and then click OK to close the Deployment
Manager:
MIDAS Library
In the Project Manager, select the mobile target platform, and run your
application. You should be able to browse data just as you do within the IDE.
See Also
o Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
o Datasnap.DSServer.TDSServer
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).
(To display Employees.s3db in the Open dialog, set the All Files (*.*) option.)
4. Select TListView.
6. Select BindSourceDB1.
LiveBindings Designer
Use the LiveBindings Designer to add new connections between the
TBindSourceDB and TListView components.
o 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).
2. Select Add Files and select the database file (for example,
C:\Users\Public\Documents\Embarcadero\Studio\18.0\Samples\Data\
Employees.s3db).
4. Select the Platforms column (double-click the ellipsis [...] in the row 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).
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.
Delphi:
See Also
o Connect to SQLite (FireDAC)
o Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android)
TButton, TSpeedButton
Using a Button Component with
Different Styles (iOS and Android) Position, Height, Width, StyleLookup, TintColor,
IconTintColor, GroupName, IsPressed
TMultiView, TDrawerAppearance
Using a MultiView Component to
Display Alternate Views of Visible, Mode, MasterButton, DoOpen, DoClose,
Information (iOS and Android) GetDisplayName, DoInstall, TargetControl,
DrawerOptions, ShadowOptions
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)
Connecting to an
DataSnap Server Wizard, TDSServerModule, TSQLConnection,
Enterprise Database
TSQLDataSet, TDataSetProvider, TDSProviderConnection,
from a Mobile Client
TClientDataSet, TListBox
(iOS and Android)
Note: This list of components is intended for informational purposes only, and
might not be entirely accurate or complete.