以下文字引自 http://www.borland.com/devsupport/bde/bdeapiex/index.html<br><br>This example will pack a Paradox or dBASE table therfore removing <br>already deleted rows in a table. This function will also regenerate <br>all out-of-date indexes (maintained indexes) This example uses the <br>following input
ackTable(Table1) <br><br>// Pack a Paradox or dBASE table<br>// The table must be opened execlusively before calling this function...<br>procedure PackTable(Table: TTable);<br>var<br> Props: CURProps;<br> hDb: hDBIDb;<br> TableDesc: CRTblDesc;<br><br>begin<br> // Make sure the table is open exclusively so we can get the db handle...<br> if Table.Active = False then<br> raise EDatabaseError.Create('Table must be opened to pack');<br> if Table.Exclusive = False then<br> raise EDatabaseError.Create('Table must be opened exclusively to pack');<br><br> // Get the table properties to determine table type...<br> Check(DbiGetCursorProps(Table.Handle, Props));<br><br> // If the table is a Paradox table, you must call DbiDoRestructure...<br> if Props.szTableType = szPARADOX then<br> begin<br> // Blank out the structure...<br> FillChar(TableDesc, sizeof(TableDesc), 0);<br> // Get the database handle from the table's cursor handle...<br> Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDATABASE, hDBIObj(hDb)));<br> // Put the table name in the table descriptor...<br> StrPCopy(TableDesc.szTblName, Table.TableName);<br> // Put the table type in the table descriptor...<br> StrPCopy(TableDesc.szTblType, Props.szTableType);<br> // Set the Pack option in the table descriptor to TRUE...<br> TableDesc.bPack := True;<br> // Close the table so the restructure can complete...<br> Table.Close;<br> // Call DbiDoRestructure...<br> Check(DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, FALSE));<br> end<br> else<br> // If the table is a dBASE table, simply call DbiPackTable...<br> if Props.szTableType = szDBASE then<br> Check(DbiPackTable(Table.DBHandle, Table.Handle, nil, szDBASE, TRUE))<br> else<br> // Pack only works on PAradox or dBASE; nothing else...<br> raise EDatabaseError.Create('Table must be either of Paradox or dBASE ' +<br> 'type to pack');<br><br> Table.Open;<br>end;