dbExpress Application Migration (FireDAC)

From RAD Studio
Jump to: navigation, search

Go Up to Migrating dbExpress Applications to FireDAC


This example shows you step by step how the Delphi demo application (MeetingOrganizer) will be migrated to FireDAC.

For this demo application, you can find the needed files in C:\Users\Public\Documents\Embarcadero\Studio\18.0\Samples\Object Pascal\Database\FireDAC\Tool\reFind\DBX2FDMigration\Demo

  • The migrate.bat utility is located in the root folder.
  • The MeetingOrganizer demo application is located in the Forms folder.
  • The MEETINGORGANIZER.GDB is located in the Database folder.
  • The dbExpress connection file (dbxconnections.ini) is located in the root folder.

Step 1: Running the Migrate.bat Utility

To run the migrate.bat utility:

  1. Go to the C:\Users\Public\Documents\Embarcadero\Studio\18.0\Samples\Object Pascal\Database\FireDAC\Tool\reFind\DBX2FDMigration\Demo folder.
  2. Double-click the migration.bat application.

The migrate.bat utility creates a new folder inside the Forms folder, called FireDAC_MeetingOrg, and copies the migrated files of the dbExpress application to the FireDAC_MeetingOrg folder. The original source files of the MeetingOrganizer application are kept in the original folder.

The migrate.bat utility runs the RAD Studio tool reFind in order to replace the dbExpress terms of the application with their FireDAC counterparts.

Step 2: Setting a FireDAC Persistent Connection Definition

The original MO dbExpress connection is defined in the dbxconnections.ini. You need to create the same FireDAC connection definition for the MeetingOrganizer demo.

To create a new FireDAC persistent connection definition you can either use the FireDAC Explorer or edit the FDConnectionDefs.ini file.

  1. Create a new FireDAC connection definition.
  2. Set the following fields of the connection:
    • Name: MO
    • DriverID: IB
    • Database: C:\Data\MEETINGORGANIZER.GDB
    • User_Name: sysdba
    • Password: masterkey
  3. Save the new connection definition.
  4. Go to C:\Users\Public\Documents\Embarcadero\Studio\18.0\Samples\Object Pascal\Database\FireDAC\Tool\reFind\DBX2FDMigration\Demo\Database
  5. Copy the Interbase MEETINGORGANIZER.GDB database to C:\Data\MEETINGORGANIZER.GDB

This is the simplest connection definition for the MeetingOrganizer application in the FDConnectionDefs.ini file:

 [MO]
 DriverID=IB
 Database=C:\Data\MEETINGORGANIZER.GDB
 User_Name=sysdba
 Password=masterkey
Note: You need to close RAD Studio.

Step 3: Preparing Your FireDAC Application for Run Time

You need to add a DBMS-specific FireDAC driver to your application and the needed units (for the IFDGUIxWaitCursor interface and the IFDPhysDriver interface).

The sample application MeetingOrganizer uses InterBase in a FireMonkey application:

  1. Go to C:\Users\Public\Documents\Embarcadero\Studio\18.0\Samples\Object Pascal\Database\FireDAC\Tool\reFind\DBX2FDMigration\Demo\Forms
  2. Open MeetingOrganizer.dproj project.
  3. In the IDE, open the uMainDM.pas unit file.
  4. Drop a TFDPhysIBDriverLink component to your project
  5. Drop a TFDGUIxWaitCursor component.

Step 4: Setting up Connection Params

Make the following changes in the uMainDM.pas file:

  1. Select the SQLConnection TFDConnection component.
  2. In the Object Inspector, change the value of ConnectionDefName to MO.
  3. Open the .dfm or the .fmx file using a text editor or press Alt+F12.
  4. Set up the TFDConnection component in the data module (modify the existing dbExpress Params.Strings).
        Params.Strings = (
          'ConnectionDef=MO'
          'Database=C:\Data\MeetingOrganizer.gdb'
          'User_Name=sysdba'
          'Password=masterkey')
    
  5. Change to the code editor or press F12.
  6. Comment the implementation of the procedure SQLConnectionBeforeConnect:
    procedure TMainDM.SQLConnectionBeforeConnect(Sender: TObject);
    begin
    //  SQLConnection.LoadParamsFromIniFile
    //    (IncludeTrailingPathDelimiter(ExtractFilePath(Application.ExeName)) +
    //    'dbxconnections.ini');
    end;
    

Step 5: Setting Data Type Mappings Compatibility

The InterBase dbExpress driver and FireDAC InterBase driver have the same data type mappings. The only exception is "[VAR]CHAR(N) CHARACTER SET OCTETS":

  • dbExpress maps it to ftString / ftWideString.
  • FireDAC maps it to ftBytes / ftVarBytes.

Still mapping and behavior may be slightly different in other areas too. To unify them:

  1. Select the SQLConnection TFDConnection component in the uMainDM.pas file.
  2. In the Object Inspector:

Step 6: Running the MeetingOrganizer Migrated Demo

The MeetingOrganizer application allows you to organize meetings for the registered users of your application in the registered rooms. Use the MeetingOrganizer application to register and modify the information of your users, conference rooms and meeting rooms.

  1. To run the application, Run or press F9.
  2. For logging on to the MeetingOrganizer application, use the following registered test user:
    • User Login: borland
    • Password: borland
Note: This is not your user to access the MEETINGORGANIZER.GDB, but a registered user of the MeetingOrganizer application.

See Also