用BCB进行多媒体数据库开发时常会发现这样一个现象,当你把一条记录从表中删除时,表的大小并没有相应减小。这样在进行多次插入删除之后,表文件就会越来越庞大。之所以会有这种现象,是因为TTable控件的 3 L5 G9 K3 B1 p" v7 `
Delete ' Z' g! `% `# H7 G9 I4 {' T
Method并不真正从表中删除记录,而只是在记录前加上一个删除标志。在DBase和Foxpro中有Pack语句对表进行压缩,但在TTable类中却没有相应的函数。其实在BDE的API函数中已经提供了DbiPackTable来对DBase或Foxpro表进行压缩,但是这个函数对Paradox的表不起作用。要想给Paradox
表减肥得用DbiDoRestructure函数来完成,以下例程完成Pack Paradox表的功能。 & |' J7 _: g& e9 m$ G& r
# j6 Z2 Z2 `$ P. _. M
//This function Pack the Paradox table. write by zodiac ; K* \$ P6 A- R1 Z' `
void __fastcall TForm1:
ackParadoxTable(hDBIDb hDB, AnsiString TblName) 5 A) e. o, y& S
{ ( R' h+ R' S7 j6 P. l
//Paradox table use a quite different way to be packed than ! ^/ p ]5 ^( K- z7 H2 M
//DBase or Foxpro table, it use the DBiDoRestructure not the
// DBiPackTable
DBIResult rslt;
CRTblDesc TblDesc; 6 z+ ^( e0 ?) q2 O' r( N* n1 N
//filled the structure CRTbiDesc with 0 ( h C k8 t+ A+ z
memset((void *)&TblDesc,0,sizeof(CRTblDesc)); 1 }4 I3 P7 ]9 `7 l* e
//copy the table name and type to the structure
lstrcpy(TblDesc.szTblName,TblName.c_str()); $ t. ^% c% [6 u2 {9 m* z: d3 E
lstrcpy(TblDesc.szTblType,szPARADOX); 6 k/ C; r8 K1 D; T9 C8 ^; u
//set bPack to true to specify Pack Function ! z+ s; _6 q- p: @! E' l9 v+ R
TblDesc.bPack=true;
//Pack the table % I$ I1 ?- W" T0 V5 I
rslt=DbiDoRestructure(hDB,1,&TblDesc,NULL,NULL,NULL,false); 9 C$ d$ `9 O8 O2 P( P$ ~& L
if(rslt!=DBIERR_NONE) 4 }9 \2 |5 h9 M: ^6 s% g8 M+ A$ s
Application->MessageBox("不能压缩表", 2 l* Q% m/ L; n' x2 M1 l
"压缩数据表出错",MB_ICONERROR);
}
注意,在Restructure之前,表必须处于关闭状态。以下例程调用PackParadoxTable. ) u2 P: t7 E4 X- v& B
" y! p* s! D# Q. Y) K/ r# U, J* P3 _
void __fastcall TForm1:
ackTable(AnsiString table_name)
{
//Pack the table
TTable *temp_table=new TTable(Form1); 2 S7 b) O1 R5 ]/ M2 n8 {
temp_table->DatabaseName="YourDatabaseAlias"; 8 Q2 _. R: D9 [3 J. t3 S+ z
temp_table->TableName=table_name; `0 G) k2 I0 _# |
temp_table->Exclusive=true; ' R5 f0 ]1 x2 S. H3 f$ U: a
temp_table->Open();
//get the Database Handle * J# [- W2 j" {. b! ?# F6 @4 ?8 H
hDBIDb hDB=temp_table->DBHandle; . Z1 O; y" s* p* S6 h2 {
temp_table->Close(); " w7 I7 K: d" g# V
+ o# E6 w- }6 p+ m; t, p0 Q
PackParadoxTable(hDB,table_name);
temp_table->Close();
temp_table->Free();
} $ o+ W- b4 J4 h$ D4 L& i$ g! R* _
6 M: N$ D& l5 i1 W+ X
对Foxpro和DBase的Pack参见BDE API Help的DbiPackTable函数说明。
| 欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) | Powered by Discuz! X2.5 |