Delphi Clinic | C++Builder Gate | Training & Consultancy | Delphi Notes Weblog | Dr.Bob's Webshop |
|
ClientDataSet XML
Using Delphi 5 Enterprise you can connect a Table to a DataSetProvider in order to feed a ClientDataSet component that can be used to store the data in .cds or .xml format.
The following console application takes a local table (in the same directory) as command-line argument, and produces an XML file containing the data:
program BDE2XML;
{$APPTYPE CONSOLE}
uses
SysUtils, DB, DBTables, Provider, DBClient;
var
Table: TTable;
DataSetProvider: TDataSetProvider;
ClientDataSet: TClientDataSet;
begin
Table := TTable.Create(nil);
try
Table.TableName := ParamStr(1);
Table.Open;
DataSetProvider := TDataSetProvider.Create(nil);
try
DataSetProvider.DataSet := Table;
ClientDataSet := TClientDataSet.Create(nil);
try
ClientDataSet.SetProvider(DataSetProvider);
ClientDataSet.Open;
ClientDataSet.SaveToFile(
ChangeFileExt(ParamStr(1),'.xml'));
ClientDataSet.Close
finally
ClientDataSet.Free
end
finally
DataSetProvider.Free
end;
Table.Close
finally
Table.Free
end
end.
Usage is really simple: make sure BDE2XML is in your path, and move to the directory where your database tables reside. Then, to convert the country.db table from Paradox to XML for example, execute:
BDE2XML country.db
The result is a 2,298 bytes country.xml file, which can be moved from Windows to Linux (by using a network, ftp or even a floppy disk) and then loaded in Kylix by a TClientDataSet component using the LoadFromFile method or the FileName property.
Alternately, you can always move your database to an InterBase database, which runs just fine on Linux.
Delphi 5 Professional
For those of you who have Delphi 5 Professional, and hence cannot make use of the TClientDataSet component, I have written a unit that can also produce ClientDataSet-compatible XML files from regular DataSets.
It was part of my Under Construction article in issue #62 of The Delphi Magazine.