An step-by-step example showing how to migrate BDE application to AnyDAC.
This example shows steps by step how the classic CodeGear demo application - MastApp - will be migrated to the AnyDAC and Oracle DBMS.
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.
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
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.
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.
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}, ......
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')
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.
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:
Now we should adjust the application source code to Oracle:
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;
|
What do you think about this topic? Send feedback!
|