Migrating from AnyDAC to FireDAC


In my last blog I explained how to migrate from ADO to FireDAC. Here I will show you how to migrate a client-server application using AnyDAC to the FireDAC. Migration from Anydac to FireDAC is very easy in compare to other migration as after acquisition of AnyDAC by Embercadero they renamed it to FireDAC. So most of functionalities are same but naming are different.

Difference
The API was renamed, including new unit names and new API prefixes.

1. For Class Names the name prefix changed from TADxxxxx to TFDxxxxx etc.

2. For FireDAC components, the name prefix changed from TADXxxx to TFDXxxx.

3. For global functions, the name prefix changed from ADXxx to FDXxx.

4. For exception classes, the name changed from EADXxx to EFDXxx.

5. For Units, hierarchical namespaces are now implemented. Unit Names are changed from uAD to FireDAC. For examples: uADCompClient -> FireDAC.Comp.Client, uADStanOption -> FireDAC.Stan.Option, uADPhysIB -> FireDAC.Phys.IB

6. Run-time packages are renamed like FireDACCommon190, FireDACCommonDriver190, FireDACADSDriver190, FireDACASADriver190, FireDACDataSnapDriver190, FireDACDb2Driver190, FireDACDBXDriver190

7. Configuration files were renamed from ADXxx.ini to FDXxx.ini and relocated to C:\Users\Public\Documents\Embarcadero\Studio\19.0\FireDAC:

8. The FireDAC configuration registry key was relocated to HKCU\Software\Embarcadero\FireDAC.

9. The key values are pointing to FireDAC configuration files: DriverFile to FDDrivers.ini, ConnectionDefFile to FDConnectionDefs.ini

So lets start in steps.

1. Units Changed
We need to replace used AnyDAC units to FireDAC units.
Find 
uADStanIntf, uADStanOption, uADStanError, uADUIIntf, uADPhysIntf, uADStanDef, uADPhys, uADStanPool, uADStanAsync, uADStanParam, uADDatSet, uADDAptIntf, uADDApt, uADCompClient, uADCompDataSet
Replace
          FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf,
FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Phys, FireDAC.Stan.Pool,
FireDAC.Stan.Async, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf,
FireDAC.DApt, FireDAC.Comp.Client, FireDAC.Comp.DataSet

2. AnyDAC components classes compatible with FireDAC
Search ANYDAC classes and replace with FireDAC classes

 ANYDAC
 FireDAC
TADConnection
TFDConnection
TADTransaction
TFDTransaction
TADTable
TFDTable
TADQuery
TFDQuery
TADStoredproc
TFDStoredproc
TADCommand
TFDCommand
TADUpdateSQL
TFDUpdateSQL

However to simplify and automate migration of Delphi applications from old to new FireDAC API, Embercadeo provides reFind utility. reFind is a command-line utility, which uses Perl Compatible Regular Expressions (PCRE) to rename entities in the files. You can find the utility in Delphi installed foxed <RAD Studio>\Bin\reFind utility.

A migration sample, located in <RAD Studio Demos> \ Delphi \ Database \ FireDAC \Tool\reFindDemo

If you want to migrate AnyDAC to FireDAC using refind utility please follow these steps :

1. Make a backup copy of your application.

2. Open the RAD Studio Command-line window.

3. Go to your project sources root folder.

4. For units and members, run the next two commands:

<RAD Studio>\Bin\reFind *.pas *.dpk *.dpr *.dproj *.inc /S /Y /I /W /B:0 /X:<RAD Studio Demos> \Delphi \Database \FireDAC \Tool \reFind \AD2FDMigration \FireDAC_Rename_Units.txt

<RAD Studio>\Bin\reFind *.pas *.dfm *.dpk *.dpr *.inc /S /Y /I /B:0 /X:<RAD Studio Demos> \Delphi \Database \FireDAC \Tool \reFind \AD2FDMigration \FireDAC_Rename_API.txt

If your application is built with run-time packages, then rename the package references according to the package names given above.
If your application is using driver configuration and/or persistent connection definition files, then rename the files according to the configuration file names given above.

Notes:
This approach does not guarantee 100% automatic and successful migration, as it is rule-based and there is not an exact, one-to-one name match. So I strongly suggest that you first create a backup copy of all your projects, although you can also use reFind to create backup copies of the changed files.




Comments

Popular posts from this blog

ShellExecute in Delphi

How to send Email in Delphi?

Drawing Shapes in Delphi