Show: Delphi C++
Display Preferences

Tutorial: Using FireDAC from a Multi-Device Application on Desktop Platforms

From RAD Studio
Jump to: navigation, search

Go Up to Database and LiveBindings Tutorials

This tutorial describes the basic steps to browse data managed by InterBase ToGo on Windows and Mac through the FireDAC framework.

Tip: Following this tutorial requires a license for IBToGo. If you are a trial user, and would like to test InterBase on Mac, you can get access to an IBToGo test deployment license during your trial. To activate your deployment trial license, please follow this link: InterBase ToGo Deployment.

Using FireDAC to Connect to the Database

FireDAC is a unique set of Universal Data Access Components for developing cross-platform database applications for Delphi, C++Builder, and FreePascal. With its powerful common architecture, FireDAC enables native high-speed direct access from Delphi to InterBase, SQLite, MySQL, SQL Server, Oracle, PostgreSQL, IBM DB2, SQL Anywhere, Access, Firebird, Informix, and more.

The FireDAC InterBase native driver supports Embarcadero InterBase Server, Desktop, Developer, ToGo, and IBLite editions version 6 and later.

  • To browse data managed by Interbase ToGo on Windows, FireDAC requires the following x86 or x64 client software to be installed on the workstation:
    • The IBTOGO.DLL library works with a database using the embedded InterBase ToGo or IBLite from x86 applications.
    • The IBTOGO64.DLL library works with a database using the embedded InterBase ToGo or IBLite from x64 applications.
  • To browse data managed by Interbase ToGo on OS X, FireDAC requires the libibtogo.dylib x86 embedded InterBase.

Design and Set Up the User Interface

Create a new project. Choose an HD Multi-Device Application.

  1. Drop a TFDConnection component on the form.
  2. Right-click the TFDConnection component and choose Connection Editor.
  3. In the FireDAC Connection Editor, set the following parameters of the TFDConnection:
    1. Set the Driver ID property to IB.
    2. Set the Database parameter to C:\Users\Public\Documents\Embarcadero\Studio\19.0\Samples\Data\EMPLOYEE.GDB (location of the database).
    3. Set the User_name parameter to sysdba.
    4. Set the Password parameter to masterkey.
      ConnectionEditor2.png

    5. Click the Test button to test the connection.
      TestConnectionSuccess.png

    6. Click OK to close the Connection Editor.
  4. In the Object Inspector, set the following properties of TFDConnection:
    1. Set the LoginPrompt property to False, so that the user is not prompted for a login.
    2. Set the Connected property to True.

Using the LiveBindings Wizard

Use the LiveBindings Wizard to add the LiveBindings components (TBindSourceDB, TBindNavigator), TFDQuery, and the Grid component.

Add the LiveBinding components

  1. Select View > LiveBindings Designer and the LiveBindings Designer opens.
  2. Select LiveBindings Wizard (LBDLiveBindingsWizard.png).
    SelectLiveBindWizard.png

  3. On the Binding task page of the wizard, select Create a data source and click Next.
  4. On the Data source page, select FireDAC and click Next.
  5. Change the Command Type to Query.
  6. Set the Command Text property to select * from employee.
    LiveBindingWizard.png

  7. Click the Test Command button.
  8. Click the Next button.
  9. Select Add data source navigator.
  10. Click the Finish button.

At this point, TBindSourceDB, TBindNavigator, and TFDQuery components were added to your form.

Add the Grid component

  1. Reopen the LiveBindings Wizard.
  2. Select Link a grid with a data source binding task.
    LinkGrid.png

  3. Click the Next button.
  4. Select TSringGrid.
  5. Click the Next button.
  6. Select BindSourceDB1.
  7. Click the Finish button to close the wizard.

Your binding diagram should look as in the following image:
Diagram.png

Preparing Your Application for Run Time

FireDAC has a loosely-coupled multilayered architecture, where layers provide services. A service API is defined as a COM interface that other layers can request using the interface factory.

To properly operate FireDAC, you must link the implementation of IFDGUIxWaitCursor and IFDPhysDriver interfaces to your application.

  1. Select the NavigatorBindSourceDB1 and set the Align property to Top.
  2. Select the StringGridBindSourceDB1 and set the Align property to Client.
  3. Drop the TFDGUIxWaitCursor and TFDPhysIBDriverLink components on the form.
    FormComponentsAdded.png

Deploying your Application to OS X

Up to this point, you have used InterBase on your desktop. This means that the actual database is located at your local hard disk drive (for example, C:\Users\Public\Documents\Embarcadero\Studio\19.0\Samples\Data\EMPLOYEES.GDB). To deploy the application on OS X, you need to copy the database file to the Mac OS file system (for example, /Users/<user>/EMPLOYEE.GDB). Also, the Interbase ToGo files must be deployed to OS X.

Deploy Interbase ToGo to OS X

  1. Open the Deployment Manager by selecting Project > Deployment.
  2. Select All-Configurations - OS X platform from the drop-down list of target platforms at the top of the Deployment Manager.
  3. Select Add Featured Files (DMgrAddFeatFiles.png):
    AddingFeaturedFiles.png

  4. Select the Interbase ToGo database module and then click OK to close the Featured Files dialog box:
    FeaturedFilesOSX.png

    You might have received from Embarcadero a license file for ToGo that has a pattern of reg_nnnnnnn.txt, where nnnnnnn is a generated number:
    • If you have saved that file over reg_ibtogo.txt (located at C:\Users\Public\Documents\Embarcadero\InterBase\redist\InterBaseXE7), you can just select the desired license.
    • If you have saved the file with its original name, then select Add Files and include the license file in the list of files that need to be deployed with the application.

Modify Your Code to Connect to a Database File on OS X

As described in the previous step, the TFDConnection component is connected to a database on Windows. So you need to replace the location of the file before connecting to the database, as follows:

  1. In the Form Designer, select the FDConnection1 component.
  2. In the Object Inspector, double-click the Value field of the BeforeConnect event.
  3. Add the following code to this event handler:

Delphi:

procedure TForm9.FDConnection1BeforeConnect(Sender: TObject);
begin
{$IFDEF MACOS}
  FDConnection1.Params.Values['Database']:= '$(DOC)/EMPLOYEE.GDB';
{$ENDIF}
end;

C++Builder:

void __fastcall TForm9::FDConnection1BeforeConnect(TObject *Sender) {
#ifdef __MACOS__
 FDConnection1->Params->Values["Database"] = "$(DOC)/EMPLOYEE.GDB";
#endif
}

Note that $(DOC) is a path variable, allowing you to simplify the writing of path expressions. On OS X, the $(DOC) points to the user home directory (/Users/<user>).

Run Your Application on Windows and OS X

Now your application is ready to run. You should be able to browse data just as you can in the IDE. You can also use the TBindNavigator component to modify the records from your database.

To run your application

  1. In Project Manager, select your target platform.
    ProjectManagerSelectTarget.png
  2. Choose either of the following commands:
    • Run > Run
    • Run > Run Without Debugging


RunTimeMac.png

See Also

Personal tools
RAD Studio 10.2 Tokyo
In other languages
Previous Versions
Assistance