TechTricks
Technical answers from the trenches 
 
 
 
 

     
   
Copying Paradox (and dBASE) Tables
 
   
 Posted: 9 May 2002
 
   
 
 Applies to: Recent versions
 
   
 
Audience: Intermediate
 
       
   

Question: How can I backup a Paradox table using Delphi? (By backup, I mean "make a copy of the data, indexes, and valchecks?")

Answer: There are several ways you can approach the problem, however, many suffer from one or more weaknesses:

  • Use a TBatchMove component and set the Mode property to batCopy.

    This only copies the data; it doesn't copy indexes, valchecks, or other family files. This may suffice for most purposes, however, it's not a "full" backup.

  • Use two TTable components. Point one to the source table (the one you wish to back up) and then assign its FieldDefs and IndexDefs properties to the target TTable. Once that's done, use a TBatchmove as above.

    This duplicates data and indexes, however, it doesn't catch all of the possible valchecks.

  • Use either the Windows API or the file routines in SysUtils to locate all files matching the name of the table (e.g. CUSTOMER.*) and then copy those to the target directory.

    This does indeed copy all family files, along with any other "extra" files that might be floating around. For example, you might have a MYTABLE.TXT file that you used to import data into the Paradox table or you might have a MYTABLE.FSL file to view/edit the data using Paradox for Windows. In other words, this may copy more files than strictly necessary.

In our experience, the most effective way to backup a Paradox (or dBASE) table is to call a function provided by the Borland Database Engine (BDE) for that purpose, as shown in the following code sample:

// Add DB, DBTables, DBIProcs to USES

procedure copyTable( const strSource, strTarget : String );
var
  hDB       : HDBIDB;     // Handle to the database
const
  OVERWRITE_FLAG = Bool( TRUE );

begin

  screen.cursor := crHourglass;
  with TTable.Create( Application ) do
  try
     // verify source table exists and grab handle
     DatabaseName := extractFilePath( strSource );
     TableName := extractFileName( strSource );
     open;
     hDB := DBHandle;
     close;

     // make the backup
     check( dbiCopyTable( hDB, OVERWRITE_FLAG,
                         pChar( strSource ), 'PARADOX',
                         pChar( strTarget ) ) );
  finally
     free;
     screen.cursor := crDefault;
  end;
end;

To use this procedure, call it using something along these lines:

copyTable( 'C:\data\pxsample\customer.db',
           'c:\temp\answer.db' );

Please note that you need to include the name of the table--and extension--in the target parameter.

Also, you should note that the above example makes certain assumptions; it assumes:

  1. You've added DB, DBTables, and DBIProcs to an appropriate USES block.

  2. The strSource and strTarget parameters contain fully qualified filenames, including path (directory/folder, not alias), name, and extension.

  3. The current user has write privileges to the target directory.

  4. We're not dealing with Universal Naming Convention (UNC) filenames.

  5. You're only copying Paradox tables.

  6. You want to completely replace any previously existing copies of the source table.

  7. You're working with Delphi 5 or later.

If one or more of these assumptions aren't appropriate for your application, adjust CopyTable() accordingly.

For more information about dbiCopyTable() and other functions provided by the BDE API, please refer to the BDE32.HLP Help file. By default, this is installed to C:\Program Files\Common Files\Borland Shared\BDE.

 

       

Top

Feedback About Paradox Delphi Assorted Web Stuff
 
 
Copyright © 2000-2004, techtricks.com; All Rights Reserved.
Acknowledgements, Disclaimers, Terms and Conditions.
Article last updated on 31 May 2003

 

Other Sites: Paradox, Delphi, Perl, Web Stuff, and More


 

[- End -]