Migrating a Database application: no BDE!

Posted by webmaster Guido

Here's an example for migrating a simple database program, removing the BDE dependancy.

A program named "Movies" has a form that contains a DBGrid. The DBGrid is connected to DataSource1, and DataSource1 is connected to a TTable component named "Movies". Movies points to the dBase file Movies.dbf, located in the same directory as the project files.

Start by making a backup copy of your old application -- zip it or copy it or whatever-- don't blame me if the migration doesn't work and you lost your data ;)

Next:

1. Add a TClientDataSet component to the form. Delphi will name it ClientDataSet1.

2.1. Right click on ClientDataSet1, and select Assign Local Data from the popup-menu that appears. Select for example the "Movies" table in the dialog that opens.

2.2. Right click again on ClientDataSet1 and select Save to MyBase XML table. Give it the name "Movies.xml". Attention: check that you select the correct directory (folder) in the dialog that appears!

3.1. Set the property Active of ClientDataSet1 to False.

3.2. In the OnCreate event handler for the form (if it doesn't exist yet, create an event handler) add the following code:

procedure TForm1.FormCreate(Sender: TObject);
begin
  Movies.LoadFromFile(ExtractFileDir(Application.ExeName) + '\Movies.xml');
  Movies.Open;
end;

3.3. Delete the TTable component.

3.4. Rename ClientDataSet1 to Movies.

3.5. Set the property DataSet of DataSource1 to Movies.

We have a tutorial on using ClientDataSet with Delphi Starter.