用BCB进行多媒体数据库开发时常会发现这样一个现象,当你把一条记录从表中删除时,表的大小并没有相应减小。这样在进行多次插入删除之后,表文件就会越来越庞大。之所以会有这种现象,是因为TTable控件的 . Y: B5 F1 J9 r! C- R7 ?/ K
Delete
Method并不真正从表中删除记录,而只是在记录前加上一个删除标志。在DBase和Foxpro中有Pack语句对表进行压缩,但在TTable类中却没有相应的函数。其实在BDE的API函数中已经提供了DbiPackTable来对DBase或Foxpro表进行压缩,但是这个函数对Paradox的表不起作用。要想给Paradox , m6 L8 a- y. N* ]) ^
表减肥得用DbiDoRestructure函数来完成,以下例程完成Pack Paradox表的功能。
/ [ x. K0 S* a
//This function Pack the Paradox table. write by zodiac
void __fastcall TForm1:
ackParadoxTable(hDBIDb hDB, AnsiString TblName) , j5 i, Z/ [* z% T: u4 V& S
{ ' l4 n0 L" Q8 a% g- p5 T1 E5 u
//Paradox table use a quite different way to be packed than : [+ N: V4 \0 q9 }9 T+ p: V
//DBase or Foxpro table, it use the DBiDoRestructure not the
// DBiPackTable
DBIResult rslt; . u% k) g, c$ V
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); + b/ h; O0 t2 r* j" O
//set bPack to true to specify Pack Function , \. i4 F; \' k) [+ B; V
TblDesc.bPack=true;
//Pack the table ) f6 Y e& g' d# \% h
rslt=DbiDoRestructure(hDB,1,&TblDesc,NULL,NULL,NULL,false);
if(rslt!=DBIERR_NONE)
Application->MessageBox("不能压缩表",
"压缩数据表出错",MB_ICONERROR);
} ) @8 g2 q; e1 @% i5 p
注意,在Restructure之前,表必须处于关闭状态。以下例程调用PackParadoxTable. + y6 ?4 }% C" F* Z' ?5 N1 z
void __fastcall TForm1:
ackTable(AnsiString table_name) ( N1 P+ Y9 n4 ?% V" ]: R
{ 4 W9 E' T5 E4 k7 ~2 v( D# C
//Pack the table
TTable *temp_table=new TTable(Form1);
temp_table->DatabaseName="YourDatabaseAlias";
temp_table->TableName=table_name;
temp_table->Exclusive=true; ( |, E3 Z( u8 i* w$ `
temp_table->Open(); : b+ \) p( i* b3 j! w" c; v
//get the Database Handle ( d* |! B( f+ [9 y8 N' p+ c
hDBIDb hDB=temp_table->DBHandle;
temp_table->Close(); $ ^6 q/ a6 j. ~# L2 h% G1 B
& _. U8 }+ s6 Y# c% e
PackParadoxTable(hDB,table_name);
4 h2 I) K! U: D& y. V6 j
temp_table->Close(); 6 U+ j- X, L- h r& l
temp_table->Free();
} - K! F# k ?# b+ l3 H( ?" y
/ W* g+ R, ~% [4 i" a3 J& a
' D" Q2 y& y( X2 ~
对Foxpro和DBase的Pack参见BDE API Help的DbiPackTable函数说明。
| 欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) | Powered by Discuz! X2.5 |