Using BCB for multimedia database development It is often found that when you delete a record from the table, the size of the file is not reduced accordingly. This makes the table file more and more large after you insert the deletion multiple times. This behavior occurs because the Ttable control's Delete method does not actually delete records from the table, but only adds a deletion flag before the record. The table is compressed with a pack statement in dBASE and FoxPro, but there are no corresponding functions in the Ttable class. In fact, the BDE API functions have provided dbipacktable to compress dBASE or FoxPro tables, but this function does not work for Paradox tables. To give the Paradox table to lose weight to use the Dbidorestructure function to complete, the following routine completes the Pack Paradox table function.
This function Pack the Paradox table. Write by Zodiac
void __fastcall TForm1::P ackparadoxtable (hdbidb HDB, ansistring tblname)
{
Paradox table use a quite different way to be packed than
DBase or Foxpro table, it use the dbidorestructure is not the
Dbipacktable
Dbiresult rslt;
Crtbldesc Tbldesc;
Filled the structure Crtbidesc with 0
memset ((void *) &tbldesc,0,sizeof (CRTBLDESC));
Copy the table name and type to the structure
lstrcpy (Tbldesc.sztblname,tblname.c_str ());
lstrcpy (Tbldesc.sztbltype,szparadox);
Set Bpack to True to specify Pack Function
Tbldesc.bpack=true;
Pack the table
Rslt=dbidorestructure (Hdb,1,&tbldesc,null,null,null,false);
if (Rslt!=dbierr_none)
Application->messagebox ("Cannot compress table", "Compress data table error", mb_iconerror);
}
Note that the table must be closed before restructure. The following routine calls Packparadoxtable.
void __fastcall TForm1::P acktable (ansistring table_name)
{
Pack the table
Ttable *temp_table=new ttable (FORM1);
Temp_table->databasename= "Yourdatabasealias";
temp_table->tablename=table_name;
temp_table->exclusive=true;
Temp_table->open ();
Get the Database Handle
Hdbidb hdb=temp_table->dbhandle;
Temp_table->close ();
Packparadoxtable (Hdb,table_name);
Temp_table->close ();
Temp_table->free ();
}
For FoxPro and dBASE packs See the Dbipacktable function description of the BDE API help.