首页  编辑  

压缩Paradox数据库

Tags: /超级猛料/Database.数据库相关/Paradox & dBase/   Date Created:

要压缩一个Paradox数据库(物理删除),请参考下面的代码!

{ METHOD: PackParadoxTable

 PURPOSE: Pack the currently opened paradox table.

}

procedure TTableEnhanced.PackParadoxTable;

var

 { Specific information about the table structure, indexes, etc. }

 TblDesc: CRTblDesc;

 { Uses as a handle to the database }

 hDb: hDbiDb;

 { Path to the currently opened table }

 TablePath: array[0..dbiMaxPathLen] of char;

begin

 hDb := nil;

 { Initialize the table descriptor }

 FillChar(TblDesc, SizeOf(CRTblDesc), 0);

 with TblDesc do

 begin

   { Place the table name in descriptor }

   StrPCopy(szTblName, TableName);

   { Place the table type in descriptor }

   StrCopy(szTblType, GetTableType);

   { Set the packing option to true }

   bPack := True;

 end;

 { Get the current table's directory.  This is why the table MUST be

   opened until now }

 Chk(DbiGetDirectory(DBHandle, True, TablePath));

 { Close the table }

 Close;

 { NOW: since the DbiDoRestructure call needs a valid DB handle BUT the

   table cannot be opened, call DbiOpenDatabase to get a valid handle.

   Setting TTable.Active = FALSE does not give you a valid handle }

 Chk(DbiOpenDatabase(nil, 'STANDARD', dbiReadWrite, dbiOpenExcl, nil,

                       0, nil, nil, hDb));

 { Set the table's directory to the old directory }

 Chk(DbiSetDirectory(hDb, TablePath));

 { Pack the PARADOX table }

 Chk(DbiDoRestructure(hDb, 1, @TblDesc, nil, nil, nil, FALSE));

 { Close the temporary database handle }

 Chk(DbiCloseDatabase(hDb));

 { Re-Open the table }

 Open;

end;