paradox和dbf数据表记录加锁(200分)

  • 主题发起人 主题发起人 zoulin
  • 开始时间 开始时间
Z

zoulin

Unregistered / Unconfirmed
GUEST, unregistred user!
请教各位大侠:
如何在程序中对paradox和dbf数据表记录加锁,不能使用抢占式方法!
 
还有要补充的是:如何在程序中判断paradox和dbf数据表的记录已经被加锁,
请给出例子。非常感谢。
 
在《DELPHI 从入门到精通中》有提到这个问题,自己看吧!
 
在《DELPHI5 从入门到精通中》有提到这个问题,自己看吧!
 
BDE有关例程

function IsRecordLocked(Table: TTable; ByAnyone: Boolean): Boolean;

var
Locked: BOOL;
hCur: hDBICur;
rslt: DBIResult;
begin
Table.UpdateCursorPos;
// Is the record locked by the current session...
Check(DbiIsRecordLocked(Table.Handle, Locked));
Result := Locked;
// If the current session does not have a lock and the ByAnyone varable is
// set to check all sessions, continue check...
if (not Result) and (ByAnyone) then begin
// Get a new cursor to the same record...

Check(DbiCloneCursor(Table.Handle, False, False, hCur));
try
// Try and get the record with a write lock...
rslt := DbiGetRecord(hCur, dbiWRITELOCK,
nil, nil);
if (rslt <> DBIERR_NONE) then begin
// if an error occured and it is a lock error, return true...
if (HiByte(rslt) = ERRCAT_LOCKCONFLICT)
then
Result := True
else
// If some other error happened, throw an exception...

Check(rslt);
end
else
// Release the lock in this session if the function was successful...
Check(DbiRelRecordLock(hCur, False));
finally
// Close the cloned cursor...
Check(DbiCloseCursor(hCur));
end;
end;
end;
 
zhanggeye
能够说明用法吗?或是举一个示例?
 
用法例程已经很清楚说明了.稍作修改直接在程序上用便可.
补充:
1.要加上BDE单元.
2.据我的测试,paradox表只有放在netware服务器上才能正确锁定.
3.我更主张用抢占式方法.

关于记录锁定,delphi很让人头痛,欢迎交流有交经验.
 
接受答案了.
 
后退
顶部