IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
Delphi
Search Delphi Group:

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

March Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingDelphi for W...Using Data   Print This     
  From the July 2011 Issue of Prestwood eMag
 
Delphi Using Data:
Reindexing and Packing dBASE and Paradox Tables
 
Posted 16 years ago on 3/13/2003 and updated 2/26/2008
Take Away: How to reindex and pack Paradox and dBASE tables.

KB100129



Reindexing and Packing Overview

You don't have to reindex your indexes as long as you created them maintained. As far as packing goes, you don't need to pack Paradox tables (automatically done for you) and you DO need to pack dBASE tables.

Packing a dBASE table

This section demonstrates how to use the BDE to pack a dBASE table. Both dBASE and FoxPro let users mark a record for deletion. The only way to permanently remove marked records is with DbiPackTable. The BDE.DbiPackTable function is the method you use to pack a dBASE table. It optimizes table space by rebuilding the table associated with hCursor and releasing any free space. Exclusive access to the table is required and it must be opened.

Here is it's syntax:
function DbiPackTable (hDb: hDBIDb; hCursor: hDBICur; pszTableName: PChar; pszDriverType: PChar; bRegenIdxs: Bool): DBIResult stdcall; 
Here are definitions of it's parameters:
  • hDb Type: hDBIDb (Input) The database handle (TTable.Database.Handle)
  • hCursor Type: hDBICur (Input) The cursor on the table (TTable.Handle). If hCursor is NULL, pszTableName and pszDriverType determine the table to be used.
  • pszTableName Type: pCHAR (Input) Pointer to the table name.
  • pszDriverType Type: pCHAR (Input) Pointer to the driver type.
  • bRegenIdxs Type: BOOL (Input) True = recreate indexes; False = don't.
Here are the DbiResult return values:
  • DBIERR_NONE The table was successfully rebuilt.
  • DBIERR_INVALIDPARAM The specified table name or the pointer to the table name is NULL.
  • DBIERR_INVALIDHNDL The specified database handle or cursor handle is invalid or NULL.
  • DBIERR_NOSUCHTABLE Table name does not exist.
  • DBIERR_UNKNOWNTBLTYPE Table type is unknown.
  • DBIERR_NEEDEXCLACCESS The table is not open in exclusive mode.
Here is a sample usage (make sure DBTables and BDE are in your uses).
procedure TForm1.PackTable(Table : TTable; ReCreateIndexes : Boolean); 
begin
 	// Make sure the table is open exclusively so we can get the db 
	// handle...
 	if not (Table.Active and Table.Exclusive) then
 		raise EDatabaseError.Create('Table must be opened exclusive to pack');
  	// DBTables.Check determines whether a value returned from the Borland
 	// Database Engine (BDE) represents an error condition. If a BDE error
 	// occurred, then DBTables.Check calls DbiError to raise an exception.
 	// BDE.DbiPackTable requires BDE to be in your uses.
  	Check(DbiPackTable(Table.Database.Handle, Table.Handle, Nil, Nil, ReCreateIndexes));
end;
Here is a sample method using the above method.
procedure TForm1.Button1Click(Sender: TObject);
begin
 	Table1.Active := False;
 	Table1.Exclusive := True;
 	Table1.Active := True;
 	PackTable(Table1, True);
end;

Comments

0 Comments.
Share a thought or comment...
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1204A1
Enter key:
KB Post Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #100129 Counter
18015
Since 4/2/2008
-
   Contact Us!
 
Have a question? Need our services? Contact us now.
--Mike Prestwood

Call: 916-726-5675

email: info@prestwood.com


Go ahead!   Use Us! Call: 916-726-5675 


©1995-2019 Prestwood IT Solutions.   [Security & Privacy]