AnyDAC
ContentsIndexHome
PreviousUpNext
BDE application migration

An step-by-step example showing how to migrate BDE application to AnyDAC.

Group
Links

This example shows steps by step how the classic CodeGear demo application - MastApp - will be migrated to the AnyDAC and Oracle DBMS. 

 

Step 1

Create a new directory. For example, ADMastApp. Later we will reference to your new directory using the ADMastApp name. Then copy MastApp source files from the Delphi Demos directory to the new one created. 

 

Step 2

Open a cmd window and change to the ADMastApp directory, or use your preferred directory manager, like FAR. Run the AnyDAC transformation tool ADDFMChanger in order to replace the BDE terms with its AnyDAC synonyms: 

 

<ADHome>\Bin\ADDFMChanger.exe *.pas *.dfm -a -f <ADHome>\Bin\BDE2AnyDAC.txt

 

Step 3

Now search in all PAS's and DFM's for all properties and methods marked for removal. The simplest way to do so is to search for the removed string. In the MastApp the single place is the DataMod.dfm. 

 

object Connection: TADConnection
  ...
  <SessionName removed> = 'Default'
  ...
end

 

Consider to remove such lines. In general, SessionName with different values may be a sign that your application requires multiple connections. 

 

Step 4

Create an AnyDAC connection definition using the AnyDAC Explorer. Then setup connection definition parameters. This is the most simple connection definition for MastApp: 

 

[MASTSQL]
DriverID=Ora
DataBase=ORA_920_APP
User_Name=ADDemo

 

NOTE: This implies that you have created an Oracle user ADDemo and loaded a DBDEMOS database (Paradox or Interbase) into the Oracle ADDemo user schema. For example, you can use the BDE's DataPump for uploading, but keep in mind that you will need to adjust the identifier registers - they must be UPPER CASE in Oracle. 

 

Step 5

Add a RDBMS specific AnyDAC driver to the application. Add one of the uADPhys[RDBMS driver ID] units to your project. E.g. if you use Oracle, add uADPhysOracle to the project. Then add aADGUIxFormsWait to your project: 

 

program Mastapp;

uses
  Forms,
  uADPhysOracle,
  uADGUIxFormsWait,
  MAIN in 'MAIN.PAS' {MainForm},
  ......

 

Step 6

Now open the DataMod.dfm file using a text editor. Setup the TADConnection component in the data module. Set ConnectionDefNam to an Oracle connection definition. Also change the user name and password to the correct one. You will then get something like this: 

 

Params.Strings = (
  'ConnectionDef=Oracle_Demo'
  'User_Name=addemo'
  'Password=a')

 

Step 7

The Interbase SQLLink and AnyDAC Oracle driver have different data type mappings, so we should adjust that to make AnyDAC type mapping compatible with BDE. Otherwise, we will need to recreate all persistent fields. To setup data mapping, we should fill up the collection property TADConnection.FormatOptions.MapRules. Lets do it in DataMod.DFM: 

 

object Database: TADConnection
......
  FormatOptions.OwnMapRules = True
  FormatOptions.MapRules = <
    item
      PrecMax = 10
      PrecMin = 0
      ScaleMax = 0
      ScaleMin = 0
      SourceDataType = dtFmtBCD
      TargetDataType = dtInt32
    end
    item
      SourceDataType = dtFmtBCD
      TargetDataType = dtDouble
    end
    item
      SourceDataType = dtDateTimeStamp
      TargetDataType = dtDateTime
    end>
......
end

 

Additionally, set FormatOptions.StrsTrim and StrsEmpty2Null properties to False, as default values for these properties are incompatible with BDE. 

 

Step 8

AnyDAC does not support desktop DB's, like Paradox or Dbase. So, we have to remove all desktop DB (Paradox, Dbase) code from the application:

  • method TMastData.UseLocalData in DataMod.pas.
  • method TMainForm.ViewLocalClick in Main.pas
  • TField.Origin property in DataMod.dfm has the format: "TABLE.DB".FieldName. We will change that to the "TABLE".FieldName, where "TABLE" is the name of the original field DB table. In most cases we can just remove "TABLE" when the query is using only a single table.

 

Step 9

Now we should adjust the application source code to Oracle:

  • In the TMainForm.ViewRemoteClick method in Main.pas, replace string ' (Local Interbase)' with ' (Oracle)'.
  • Remove the TMainForm.ViewMenuClick handler in Main.pas.
  • Remove the TMastData.DataDirectory method in DataMod.pas.
  • The application creates a DB connection definition on the fly if it does not exist. So, change the TMastData.UseRemoteData in the DataMod.pas to:

 

procedure TMastData.UseRemoteData;
var
  Params: TStringList;
begin
  { See if the ConnectionDef exists.  If not, add it. }
  if not ADManager.IsConnectionDef('MASTSQL') then
  begin
    Params := TStringList.create;
    try
      Params.Values['DATABASE'] := 'APPOR920_LSNR';
      Params.Values['USER NAME'] := 'MASTAPP_DB';
      ADManager.AddConnectionDef('MASTSQL', 'ORA', Params);
    finally
      Params.Free;
    end;
  end;
  SetDatabaseConnectionDef('MASTSQL');
end;

 

  • We have to adjust the SQL commands used by applications. In DataMod query CustByLastInvQuery has the DESCENDING key word, but Oracle uses DESC.
What do you think about this topic? Send feedback!