views:

360

answers:

5

How to generate DBF files with delphi?

More information:

I need a portable Database to run in a pendrive

I don't know if DBF is the better soluttion.

I like MySql but is hard to find a portable version

I am working with XML at this time but I don't know how to make a Query.

+1  A: 

Not dealt with that in years!
Depending on your version of Delphi and what you want to do, you can either use the BDE or find some specialized components that read/write directly to DBF native file format.

François
+1  A: 

While I haven't used it, there is a component jdDbf which appears to be recently updated that appears that it will work. Something to be aware of is that the Dbf format has many flavors, however most of the variances appear to be in the index files so if you need to use it with another system you might have to rebuild them.

For a embedded database that works well on a usb drive, I would look at SQLite. There is a Delphi implementation DISQLite3 which has a free and pro version that would work well and comes highly recommended. There are many commercial quality programs currently using it, including the likes of FeedDemon.

skamradt
+1  A: 

Wow, I'm amazed this url is still valid!

If you want to create a DBF with the BDE API, you can use the techniques here: http://info.borland.com/devsupport/bde/bdeapiex/dbicreatetable.html

However, depending on the size of the dataset you're going to have, this sounds like a single-user app, which would work just fine with a "MyBase" file -- another name for the files used by TClientDataSet. You can save it either as XML or binary (CDS) format by simply setting the TClientDataSet.FileName property, which will be used to read and write the dataset. You can even create nested datasets with this.

If you want to have the most efficient single user mode, also turn off the ChangeLog on the TClientDataSet.

procedure TFormCDSDataBug.ButtonOpenClick(Sender: TObject);
begin
  ClientDataSet1.FileName := ExtractFilePath(Application.ExeName) + 'MyData.cds';
  ClientDataSet1.LogChanges := False;
  ClientDataSet1.Open;
end;
John Kaster
+2  A: 

If you are open to alternative formats, I would strongly recommend you check out Firebird embedded. I'm pretty sure I loaded my database and my application on a flash drive as an experiment about two years ago and it ran fine. I stuck with DBF files for a long time, but once I made the switch, I would never go back. If you want to give this a try, consider using DBExpress and the Interbase driver. Although it's not officially supported, I have not found any incompatibilities. For a visual management tool, get the personal edition of IBExpert.

Using SQLite would be another good option. DB compiles right into the executable. All you have to deploy is exe and db file, no installation required
Joe Meyer
+1 for SQLite - it's becoming a de-facto standard for embedded DBs..
Michael Pliskin
+3  A: 

TDBF seems to be one of the most used (and still maintained) packages:

http://tdbf.sourceforge.net/

Marco van de Voort