首页  编辑  

是否显示dBase中已经删除的记录

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

如果要显示已经删除的记录怎么办?

使用下面的类似的代码即可:

注意:应该在Table的AfterOpen之后调用这个函数!

procedure SetDelete(oTable:TTable; Value: Boolean);

var

 rslt: DBIResult;

 szErrMsg: DBIMSG;

begin

 try

   oTable.DisableControls;

   try

     rslt := DbiSetProp(hDBIObj(oTable.Handle), curSOFTDELETEON,

     LongInt(Value));

     if rslt <> DBIERR_NONE then

     begin

       DbiGetErrorString(rslt, szErrMsg);

       raise Exception.Create(StrPas(szErrMsg));

     end;

   except

     on E: EDBEngineError do ShowMessage(E.Message);

     on E: Exception do ShowMessage(E.Message);

   end;

 finally

   oTable.Refresh;

   oTable.EnableControls;

 end;

end;

**********************

// 判断Atable 中当前记录是否已被删除, 若返回值为True 则已被删除,

否则未被删除

Function GetDelFlag(Atable: Ttable):Boolean;

var

CP: CurProps;

RP: RecProps;

begin

with Atable do begin

UpdateCursorPos; // 同步 BDE 和 Delphi

Check(DbiGetCursorProps(Handle, CP));

// 确认是Dbase 表!且已置软删除

if CP.szTableType<>szDBASE then

raise EDatabaseError.Create('Not is DBASE DBF!');

if CP.bDeletedOn = False then

raise EDatabaseError.Create('Soft deletes is not on');

// 取出删除标记

Check(DbiGetRecord(Handle, dbiNOLOCK, nil, @RP));

GetDelFlag := RP.bDeleteFlag;

end;

end;

// 设置软删除标记.

// 若使SofeDelete=True 则使BDE 不过滤有"*"标记记录,否则,过滤

procedure SetSofDelete(Table: Ttable; SoftDelete: Boolean);

var

rslt: DBIResult;

Props: CURProps;

begin

Check(DbiGetCursorProps(Table.Handle, Props));

// 确认是Dbase 表

if StrIComp(Props.szTableType, szDBASE) <> 0 then

raise EDBEngineError.Create(DBIERR_NOTSUPPORTED);

// 确认能设置软删除

rslt := DbiValidateProp(hDBIObj(Table.Handle), curSOFTDELETEON,SoftDelete);

if rslt = DBIERR_NONE then

// 设置软删除

Check(DbiSetProp(hDBIObj(Table.Handle), curSOFTDELETEON, Longint(SoftDelete)))

else

raise EDBEngineError.Create(rslt);

end;

// 允许有"*"标记记录显示

procedure DispDeleted(Table: Ttable);

Begin

SetSofDelete(Table,True );

End;

// 不允许有"*"标记记录显示

procedure UndispDeleted(Table: Ttable);

Begin

SetSofDelete(Table,False );

End;

// 恢复删除

procedure Undel(dBASETbl: Ttable);

var

Cprops: CurProps;

begin

Check(DbiGetCursorProps(dBASETbl.Handle, Cprops));

// 确认是Dbase 表,且软删除已设置为True;

if StrIComp(Cprops.szTableType, szDBASE) <> 0 then

raise EDBEngineError.Create(DBIERR_NOTSUPPORTED);

if Cprops.bDeletedOn = False then

raise EDatabaseError.Create('Soft deletes is not on');

Check(DbiUndeleteRecord(dBASETbl.Handle));

end;

procedure TForm1.Button1Click(Sender: Tobject);

begin

Table1.Active:=True;

DispDeleted(Table1);

end;

procedure TForm1.Button3Click(Sender: Tobject);

begin

Undel(Table1);

end;

procedure TForm1.Button4Click(Sender: Tobject);

begin

GetDelFlag(Table1);

end;

end.