发信人: teleme(GateWay)
整理人: teleme(2001-02-26 08:53:47), 站内信件
|
Pack一个dBASE 数据库需要调用BDE函数DbiPackTable。下面我将会用一个例子来说明如何使用这个函数,包括错误检测。要使用DbiPackTable函数,调用的单元必须在Uses部分包含DbiTypes,DbiErrs,DbiProcs。如果函数失败,它不会产生一个错误消息,所以为了判断是成功还是失败,你必须自己检查函数的返回值,如果函数成功,它返回DBIERR——NONE,否则返回预定的值,通过这个返回值,我们可以知道错误的原因并且如何去解决它。下面是一个例子:
procedure TForm1.Button1Click(Sender: TObject);
var
Error: DbiResult;
ErrorMsg: String;
Special: DBIMSG;
begin
table1.Active := False;
try
Table1.Exclusive := True;
Table1.Active := True;
Error := DbiPackTable(Table1.DBHandle, Table1.Handle, nil, szdBASE, True);
Table1.Active := False;
Table1.Exclusive := False;
finally
Table1.Active := True;
end;
case Error of
DBIERR_NONE:
ErrorMsg := 'Successful';
DBIERR_INVALIDPARAM:
ErrorMsg := 'The specified table name or the pointer to the table name is NULL';
DBIERR_INVALIDHNDL:
ErrorMsg := 'The specified database handle or cursor handle is invalid or NULL';
DBIERR_NOSUCHTABLE:
ErrorMsg := 'Table name does not exist';
DBIERR_UNKNOWNTBLTYPE:
ErrorMsg := 'Table type is unknown';
DBIERR_NEEDEXCLACCESS:
ErrorMsg := 'The table is not open in exclusive mode';
else
DbiGetErrorString(Error, Special);
ErrorMsg := '[' + IntToStr(Error) + ']: ' + Special;
end;
MessageDlg(ErrorMsg, mtWarning, [mbOk], 0);
end;
|
|